You can apply the .scrollContentBackground(.hidden)
modifier to a List
or Form
to apply a background colour to them.
List
and Form
are both built from UITableView
, so they have commonly inherited properties, and one of them, is the default system background.
You might notice that you are going to be shown the default background colour even if you applied a different colour. To fix this, you need to apply the .scrollContentBackground(.hidden)
modifier first before applying another .background()
modifier. This way, it tells SwiftUI to remove the default background first before applying a custom background.
Something like this
List {
ForEach(todos, id: \.self) { todo in
Text(todo)
}
}
.scrollContentBackground(.hidden) // remove system background first
.background(Color.blue)
Top comments (0)