I can't change background color of a view if i List static items. this my code:
NavigationView {
ZStack {
Color("AppBackgroundColor").edgesIgnoringSafeArea(.all)
List {
Section(header: Text("Now in theaters")) {
ScrollMovies(type: .currentMoviesInTheater)
}
Section(header: Text("Popular movies")) {
ScrollMovies(type: .popularMovies)
}
}.listStyle(.grouped)
}
}
You can provide a modifier for the items in the list
since, you are asking for changing the background color of view,
you can use
.colorMultiply()
for that.Code:
Output:
PlaygroundPage.current.liveView = UIHostingController(rootView: ContentView())
All SwiftUI's
List
s are backed by aUITableView
in iOS. so you need to change the background color of the tableView. But sinceColor
andUIColor
values are slightly different, you can get rid of theUIColor
.Now you can use Any background (including all
Color
s) you wantNote that those top and bottom white areas are the safe areas and you can use the
.edgesIgnoringSafeArea()
modifier to get rid of them.Also note that
List
with the.listStyle(GroupedListStyle())
modifier can be replaced by a simpleForm
. But keep in mind that SwiftUI controls behave differently depending in their enclosing view.Easiest way to do this for now is just to use UIAppearance proxy. SwiftUI is young so there's a couple of features not fully implemented correctly by Apple yet.
UITableView.appearance().backgroundColor = .red