Post

Replies

Boosts

Views

Activity

Setting background color of whole View in SwiftUI when using NavigationView
How can I set the background color of the whole view to a particular Color? I tried different solutions, e.g., NavigationView { ZStack { Color.green .edgesIgnoringSafeArea(.all) } ... } which does nothing. or init{ UINavigationBar.appearance().backgroundColor = .green } which sets only the navigation bar (upper part) to the particular color Here is my ContentView which looks as follows: import TabularData struct ContentView: View {         var model = DataModel.shared   @State private var searchText = ""       var body: some View {     NavigationView{       let headers: [String] = model.dataTable!.columns.map { $0.name }.sorted(by: <)               VStack{         List{           ForEach(headers.indices, id:\.self) { index in             if index != 0{               NavigationLink(destination: ActivityDetailView(header: headers[index])){                 Text(headers[index])               }               .listRowBackground(                 ((index % 2 == 0) ? Color.white : Color("customYellow"))                   .cornerRadius(10)               )             }           }         }.searchable(text: $searchText)       }       .navigationTitle("Choose Activity")     }   } } struct ContentView_Previews: PreviewProvider {   static var previews: some View {     ContentView()   } } Addition And if possible, I want to set a gradient for the whole view as background color let backgroundGradient = LinearGradient( gradient: Gradient(colors: [Color.green, Color.blue]), startPoint: .top, endPoint: .bottom)
3
0
8.2k
Mar ’23
Showing Current Location with WKWebView by using SwiftUI - How to Prevent Duplicate Permission Request for Location
How to implement a WKWebView in SwiftUI which is not asking two times for the permission of the location? I use Xcode 14.0.1 and Swift Version 5.7. In Xcode under Info in Custom iOS Target Properties, I added the Key Privacy - Location When In Use Usage Description which is responsible for the first permission prompt. I just want to show this prompt (as it works when I use Cordova). The following code import SwiftUI import WebKit struct ContentView: View {   var body: some View {     WebView()   } } struct ContentView_Previews: PreviewProvider {   static var previews: some View {     ContentView()   } } struct WebView: UIViewRepresentable {   func makeUIView(context: Context) -> WKWebView {     let webView = WKWebView()     return webView   }       func updateUIView(_ webView: WKWebView, context: Context) {     webView.load(URLRequest(url: URL(string: "https://www.openstreetmap.org")!))   } } shows the following two permission prompts First permission prompt (which is correct) Second permission prompt (which should be avoided) I also tried the solution from stackoverflow which did not work.
0
1
2.2k
Oct ’22
How to get a DataFrame of first n elements and last n elements from a sorted DataFrame
I have the following CSV Data which is loaded into a DataFrame: import Foundation import TabularData func main() {   let csv = """     Text,Value     Frog,47     Duck,11     Horse, 11     Bee, 12     Spider,55     Flower,1     Tree,100     """   var df = try! DataFrame(csvData: Data(csv.utf8))   df = df.sorted(on: "Value", order: .descending)       print(df)   /*Prints    ┏━━━┳━━━━━━━━━━┳━━━━━━━━━━┓    ┃   ┃ Text    ┃ Value   ┃    ┃   ┃ &lt;String&gt; ┃ &lt;Double&gt; ┃    ┡━━━╇━━━━━━━━━━╇━━━━━━━━━━┩    │ 0 │ Tree    │  100,0 │    │ 1 │ Spider  │   55,0 │    │ 2 │ Frog    │   47,0 │    │ 3 │ Bee    │  12,0 │    │ 4 │ Duck    │   11,0. │    │ 5 │ Horse   │   11,0 │    │ 6 │ Flower  │   1,0 │    └───┴──────────┴──────────┘        */       } main() I want, for example, only the first two and last two elements from the DataFrame above: ┏━━━┳━━━━━━━━━━┳━━━━━━━━━━┓ ┃   ┃ Text    ┃ Value   ┃ ┃   ┃ &lt;String&gt; ┃ &lt;Double&gt; ┃ ┡━━━╇━━━━━━━━━━╇━━━━━━━━━━┩ │ 0 │ Tree    │  100,0 │ │ 1 │ Spider  │   55,0 │ │ 2 │ Horse   │   11,0 │ │ 3 │ Flower  │   1,0 │ └───┴──────────┴──────────┘
1
1
1k
Sep ’22