Skip to main content
.listRowBackground(content: Component): Component
content
Component
required
The component to display as the row’s background.

Support

Usage

Colored row background

Apply to content inside a List’s ForEach.
List([
    ForEach(items, (item) =>
        Text(item.name)
            .listRowBackground(Color("blue").opacity(0.1))
    )
])

Alternating row backgrounds

List([
    ForEach(items, (item, index) =>
        Text(item.name)
            .listRowBackground(
                index % 2 === 0
                    ? Color("gray").opacity(0.1)
                    : Color("white")
            )
    )
])

Notes

  • This modifier should be applied to the content views inside a List, not to the List itself.
  • The background fills the entire row area, including under any separators.

See Also