List
:All SwiftUI's List
s are backed by a UITableView
in iOS. so you need to change the background color of the tableView. But since Color
and UIColor
values are slightly different, you can get rid of the UIColor
.
struct ContentView : View {
init(){
UITableView.appearance().backgroundColor = .clear
}
var body: some View {
List {
Section(header: Text("First Section")) {
Text("First Cell")
}
Section(header: Text("Second Section")) {
Text("First Cell")
}
}
.background(Color.yellow)
}
}
Now you can use Any background (including all Color
s) you want
Also First look at this result:
As you can see, you can set the color of each element in the View hierarchy like this:
struct ContentView: View {
init(){
UINavigationBar.appearance().backgroundColor = .green
//For other NavigationBar changes, look here:(https://stackoverflow.com/a/57509555/5623035)
}
var body: some View {
ZStack {
Color.yellow
NavigationView {
ZStack {
Color.blue
Text("Some text")
}
}.background(Color.red)
}
}
}
And the first one is window
:
window.backgroundColor = .magenta
The very common issue is we can not remove the background color of SwiftUI's HostingViewController
(yet), so we can't see some of the views like navigationView
through the views hierarchy. You should wait for the API or try to fake those views (not recommended).