listRowBackground(_:)
Places a custom background view behind a list row item.
Declaration
nonisolated func listRowBackground<V>(_ view: V?) -> some View where V : View
Parameters
- view:
The View to use as the background behind the list row view.
Return Value
A list row view with view as its background view.
Discussion
Use listRowBackground(_:) to place a custom background view behind a list row item.
In the example below, the Flavor enumeration provides content for list items. The SwiftUI ForEach structure computes views for each element of the Flavor enumeration and extracts the raw value of each of its elements using the resulting text to create each list row item. The listRowBackground(_:) modifier then places the view you supply behind each of the list row items:
struct ContentView: View {
enum Flavor: String, CaseIterable, Identifiable {
var id: String { self.rawValue }
case vanilla, chocolate, strawberry
}
var body: some View {
List {
ForEach(Flavor.allCases) {
Text($0.rawValue)
.listRowBackground(Ellipse()
.background(Color.clear)
.foregroundColor(.purple)
.opacity(0.3)
)
}
}
}
}[Image]