Instance Method

listRowInsets(_:)

Applies an inset to the rows in a list.

Declaration

func listRowInsets(_ insets: EdgeInsets?) -> some View

Parameters

insets

EdgeInsets to apply to the edges of the view.

Return Value

A view that uses the given edge insets when used as a list cell.

Discussion

Use listRowInsets(_:) to change the default padding of the content of list items.

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 listRowInsets(_:) modifier changes the edge insets of each row of the list according to the EdgeInsets values you provide.

struct ListRowInsets: 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)
        }
        .listRowInsets(EdgeInsets(top: 0, leading: 75, bottom: 0, trailing: 0))
    }
}

See Also

Configuring a List View

func listRowBackground<V>(V?) -> View

Places a custom background view behind a list row item.

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.