I would like to change the background color of List rows in SwiftUI but can't quite figure it out. Here's a simpler version of the code I've written so far.
struct ContentView: View {
init() {
UINavigationBar.appearance().titleTextAttributes = [NSAttributedString.Key.foregroundColor:UIColor.black]
UINavigationBar.appearance().barTintColor = .blue
}
var body: some View {
NavigationView {
ZStack {
HStack {
List(0...10) { test in
Spacer()
self.background(Color.purple)
Text("This is a test")
Spacer()
self.background(Color.pink)
}
.background(Color.blue)
List(0...10) { test2 in
Spacer()
Text("Also a test")
.background(Color.green)
Spacer()
}
.background(Color.red)
}
}
}
.navigationBarTitle(
Text("Test"),
displayMode: .inline
)
}
}
I'd like only the cell/row backgrounds to change color, but they stay white in light mode and black in dark mode.