TechnologiesSwiftUI

NavigationSplitViewStyle protocol

iOSmacOStvOSwatchOSvisionOSiOS 16.0+✓ renders

A type that specifies the appearance and interaction of navigation split

How it works

A type that conforms to NavigationSplitViewStyle describes how a NavigationSplitView arranges and prioritizes its columns. SwiftUI applies a default style automatically, so you only adopt one when you want to override how the sidebar, content, and detail columns share space and how they collapse on compact widths. Rather than constructing a style value directly, you select one of the built-in styles through the navigationSplitViewStyle(_:) modifier, which writes the chosen style into the environment for the enclosing split view to read.

  1. Build the column layout the style governs

    NavigationSplitViewStyle only takes effect on a NavigationSplitView, so the style needs columns to act on. Here the sidebar column is a List of folders and the trailing detail: column shows the current selection; the style decides how these two columns are laid out and which one is emphasized.

  2. Apply a style with navigationSplitViewStyle(_:)

    You attach a style by calling .navigationSplitViewStyle(_:) on the NavigationSplitView. The modifier accepts any value conforming to NavigationSplitViewStyle and places it into the environment, where the split view resolves it when laying out its columns. In the example this is .navigationSplitViewStyle(.balanced).

  3. Choose among the built-in conforming styles

    SwiftUI ships concrete conformances you reference through static members instead of initializing yourself: .automatic for the system default, .balanced to give the detail column room while keeping the leading columns visible, and .prominentDetail to favor the detail column so it stays full-width even when a leading column is showing. The demo selects .balanced.

  4. Let the style drive collapse behavior

    Because the style is read by the NavigationSplitView, it also influences how columns overlay or collapse as available width shrinks. The same selection binding that drives the List and the detail: content keeps working unchanged; switching the style changes only the spatial arrangement, not the data flow.

Try it — Change .navigationSplitViewStyle(.balanced) to .navigationSplitViewStyle(.prominentDetail) and watch the detail column stay full-width while the Mailboxes sidebar overlays instead of pushing it aside.

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.

NavigationSplitViewStyle.swift
struct NavigationSplitViewStyleDemo: View {
    @State private var selection: String? = "Inbox"
    let folders = ["Inbox", "Sent", "Drafts"]
    var body: some View {
        NavigationSplitView {
            List(folders, id: \.self, selection: $selection) { folder in
                Text(folder)
            }
            .navigationTitle("Mailboxes")
        } detail: {
            Text(selection ?? "No selection")
                .font(.title)
                .padding()
        }
        .navigationSplitViewStyle(.balanced)
    }
}
Live preview
folder Inbox
folder Inbox
swift → lexer → parser → sema → uiir → canvas Open in Studio ↗
What's new in SwiftUI 27 →