Updated for Xcode 14.0 beta 1
SwiftUI has a dedicated modifier for setting background views behind list rows, called listRowBackground()
. This accepts any kind of view – including colors, images, and shapes – and uses it behind rows.
For example, this creates a list using 10 rows, each with a red background color:
List {
ForEach(0..<10) {
Text("Row \($0)")
}
.listRowBackground(Color.red)
}
Download this as an Xcode project
Tip: listRowBackground()
won’t affect any parts of the list that don’t contain data.
SPONSORED In-app subscriptions are a pain. The code can be hard to write, hard to test, and full of edge cases. RevenueCat makes it straightforward and reliable so you can get back to building your app.
Sponsor Hacking with Swift and reach the world's largest Swift community!
Link copied to your pasteboard.