How it works
InsetListStyle is the list style that pulls each row in from the leading and trailing edges of the list, giving content a margin of breathing room rather than running it edge to edge. Reach for it when you want a List to read as a set of indented rows—a common look for inboxes, settings, and detail screens on iOS—without manually padding every row yourself. It conforms to ListStyle, so you never construct it for its own sake; you hand it to a List through the listStyle(_:) modifier, and SwiftUI applies the inset metrics, including the appropriate alignment of section headers and separators.
Apply the style with .listStyle(.inset)
The entry point is the listStyle(_:) modifier on a List, which accepts any ListStyle value. Passing the .inset shorthand selects InsetListStyle, telling SwiftUI to indent the rows from both edges. In the example,
.listStyle(.inset)is attached to theListto switch it from the platform default to the inset presentation.Let the List be the container it modifies
InsetListStyle only has meaning when applied to a
List, which is the view whose rows it insets. The style governs how that list lays out and aligns its content, so the modifier belongs on the List itself rather than on any individual row inside it.Watch how it insets section headers and separators
Because the style insets the whole row, content organized into a
Sectiongets its header and row separators aligned to the new inset margin too. TheSection("Inbox")header and its rows shift inward together, keeping the header text lined up with the indented row content.Use ordinary row content unchanged
InsetListStyle changes the framing of the list, not the rows you put in it, so existing row views need no modification. The
Label("Welcome aboard", systemImage: "envelope")rows render exactly as they would in any list and simply pick up the inset margin from the style.
.listStyle(.inset) to .listStyle(.plain) and watch the rows snap back to the full width of the list, with the leading and trailing margins disappearing.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.
struct InsetListStyleDemo: View {
var body: some View {
List {
Section("Inbox") {
Label("Welcome aboard", systemImage: "envelope")
Label("Your receipt", systemImage: "doc.text")
Label("Weekend sale", systemImage: "tag")
}
}
.listStyle(.inset)
}
}