TechnologiesSwiftUI

SidebarRowSize enum

iOSmacOStvOSwatchOSvisionOSiOS 16.0+✓ renders

The standard sizes of sidebar rows.

How it works

SidebarRowSize is an enumeration that describes the standard control sizes a sidebar uses to lay out its rows, letting you choose between compact, medium, and large row metrics. SwiftUI reads this value from the environment when rendering a sidebar-style List, scaling row height, label spacing, and the size of leading icons to match. Reach for it when the default density doesn't fit your content — for example, to give a navigation sidebar a roomier, touch-friendly feel, or to tighten it up so more items are visible at once.

  1. Pick a row size from the SidebarRowSize cases

    SidebarRowSize is a frozen enum whose cases name the available densities — small, medium, and large. Each case maps to a system-defined set of metrics for row height and icon sizing, so you express intent ("give me large rows") rather than hardcoding point values. In the example the choice is .large, the most spacious option.

  2. Apply it through the sidebarRowSize environment key

    You don't set SidebarRowSize on a view directly; you publish it into the environment with the \.sidebarRowSize key value, and the enclosing sidebar reads it when laying out its rows. Here .environment(\.sidebarRowSize, .large) is attached to the List, telling every row inside that list to adopt the large metrics.

  3. Let the rows inherit the value

    Because the size travels through the environment, it propagates to the descendants of the view it's set on without each row opting in. The three Label rows — "Inbox", "Sent", and "Archive" — pick up the .large sizing automatically, growing their height and the systemImage glyphs to match the chosen density.

  4. Combine it with the sidebar list style

    SidebarRowSize takes effect where SwiftUI draws sidebar-style rows, so it pairs with a List presented as a sidebar (for instance inside a NavigationSplitView column). The List in the example is the surface that interprets the value; placing the .environment modifier on that list is what scopes the row size to exactly those rows.

Try it — Change .environment(\.sidebarRowSize, .large) to .medium or .small and watch the row height and the systemImage icons in the three Labels shrink to a denser layout.

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.

SidebarRowSize.swift
struct SidebarRowSizeDemo: View {
    var body: some View {
        List {
            Label("Inbox", systemImage: "tray")
            Label("Sent", systemImage: "paperplane")
            Label("Archive", systemImage: "archivebox")
        }
        .environment(\.sidebarRowSize, .large)
        .padding()
    }
}
Live preview
Inbox Sent Archive
Inbox Sent Archive
swift → lexer → parser → sema → uiir → canvas Open in Studio ↗
What's new in SwiftUI 27 →