TechnologiesSwiftUILists and Collections

ListStyle protocol

iOSmacOStvOSwatchOSvisionOSiOS 13.0+✓ renders

A protocol that describes the behavior and appearance of a list.

How it works

ListStyle is the protocol that describes how a list presents itself: the spacing of its rows, the treatment of its section headers, the inset and background behind its content, and the platform-idiomatic chrome that frames it all. Rather than configuring those details by hand on every list, you select a conforming style and let SwiftUI apply a coherent appearance for you. Reach for ListStyle when you want a list to read as plain, grouped, inset, or sidebar — switching between built-in looks without touching the list's structure or its data.

  1. Apply a style with the listStyle(_:) modifier

    You don't conform to ListStyle yourself; you choose a value of a conforming type and hand it to the listStyle(_:) modifier. The modifier attaches the style to the enclosing List and to any lists nested in its hierarchy. In the example, .listStyle(.insetGrouped) is applied to the List, which selects the inset, grouped presentation for its rows.

  2. Pick a built-in conforming style

    SwiftUI ships several types that conform to ListStyle — each a distinct visual language: plain, grouped, inset, inset-grouped, and sidebar among them. You refer to them through leading-dot shorthand on the modifier, so .insetGrouped resolves to InsetGroupedListStyle. Swapping that single token is all it takes to move between looks.

  3. Let the style shape sections

    Because the style owns header and grouping treatment, the way you structure content with Section is interpreted by ListStyle rather than styled by you. The Section("Fruits") and Section("Veggies") groups gain their inset cards, rounded corners, and header styling from the chosen .insetGrouped style — the same sections would render as flush, full-width rows under .plain.

  4. Keep row content style-agnostic

    Rows describe their content, not their framing, so the list's contents stay the same across every style. The Label("Apple", systemImage: "applelogo") rows declare text and a symbol; ListStyle decides their insets, separators, and backgrounds. This separation is what lets one style be substituted for another without editing a single row.

Try it — Change .listStyle(.insetGrouped) to .listStyle(.plain) and watch the inset section cards flatten into flush, full-width rows.

Example & preview

Press Run live & edit to compile it in your browser — then edit the Swift on the left and the preview re-renders live.

ListStyle.swift
struct ListStyleDemo: View {
    var body: some View {
        List {
            Section("Fruits") {
                Label("Apple", systemImage: "applelogo")
                Label("Banana", systemImage: "leaf")
            }
            Section("Veggies") {
                Label("Carrot", systemImage: "carrot")
            }
        }
        .listStyle(.insetGrouped)
    }
}
Live preview
Fruits Apple Banana Veggies Carrot
Fruits Apple Banana Veggies Carrot
swift → lexer → parser → sema → uiir → canvas Open in Studio ↗
What's new in SwiftUI 27 →