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)