Declaration
compose().listRowBackground(view: ReactNode | null)nonisolated func listRowBackground<V>(
_ view: V?
) -> some View
where V : ViewParameters
view*ReactNode | nullThe
Viewto 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)
)
}
}
}
}See also
More in Lists and tables.
- deleteDisabledAdds a condition for whether the view's view hierarchy is deletable.
- listItemTintSets the tint effect for content in a list.
- listRowInsetsSets the insets of rows in a list on the specified edges.
- listRowSeparatorSets the display mode for the separator associated with this specific row.
- listRowSeparatorTintSets the tint color associated with a row.
- listRowSpacingSets the vertical spacing between two adjacent rows in a List.
- listSectionIndexVisibilityChanges the visibility of the list section index.
- listSectionMarginsSet the section margins for the specific edges.
- listSectionSeparatorSets whether to hide the separator associated with a list section.
- listSectionSeparatorTintSets the tint color associated with a section.
- listSectionSpacingSets the spacing between adjacent sections in a List to a custom value.
- moveDisabledAdds a condition for whether the view's view hierarchy is movable.