Generic Instance Method

listRowBackground(_:)

Places a custom background view behind a list row item.

Declaration

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 List builder iterates over the Flavor enumeration and extracts the raw value of each of its elements using the resulting text to create each list row item. After the list builder finishes, the listRowBackground(_:) modifier places the view you supply behind each of the list row items.

struct ListRowBackground: View {

    enum Flavor: String, CaseIterable, Identifiable {
        var id: String { self.rawValue }
        case vanilla, chocolate, strawberry
    }

    var body: some View {
        List(Flavor.allCases, id: \.self) {
            Text($0.rawValue)
        }
        .listRowBackground(Image(systemName: "sparkles"))
    }
}

See Also

Configuring a List View

func listRowInsets(EdgeInsets?) -> View

Applies an inset to the rows in a list.

func listRowPlatterColor(Color?) -> View

Sets the color that the system applies to the row background when this view is placed in a list.

func tag<V>(V) -> View

Sets the unique tag value of this view.