How to set the background color of list rows using listRowBackground()
About 2 min
How to set the background color of list rows using listRowBackground() 관련
SwiftUI by Example
Back to Home
How to set the background color of list rows using listRowBackground() | SwiftUI by Example
How to set the background color of list rows using listRowBackground()
Updated for Xcode 15
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)
}
Tips
listRowBackground()
won't affect any parts of the list that don't contain data.
Similar solutions…
How to change the tint color for individual list rows | SwiftUI by Example
How to change the tint color for individual list rows
How to let users delete rows from a list | SwiftUI by Example
How to let users delete rows from a list
How to let users move rows in a list | SwiftUI by Example
How to let users move rows in a list
How to add a badge to TabView items and List rows | SwiftUI by Example
How to add a badge to TabView items and List rows
How to change the background color of List, TextEditor, and more | SwiftUI by Example
How to change the background color of List, TextEditor, and more