TechnologiesSwiftUI

ToolbarMinimizeBehavior struct

iOSmacOStvOSwatchOSvisionOS✓ renders

The minimize behavior of a toolbar.

How it works

ToolbarMinimizeBehavior describes when a toolbar should collapse its items into a compact, minimized form rather than displaying them at full size. It lets you trade toolbar prominence for content space, deciding whether the bar stays expanded, condenses automatically, or condenses in response to scrolling. Reach for it when a toolbar competes with scrollable content for vertical room and you want the system to reclaim that room as the reader moves through the view.

  1. Apply the behavior with toolbarMinimizeBehavior(_:)

    The view modifier toolbarMinimizeBehavior(_:) attaches a ToolbarMinimizeBehavior to the toolbar of the view it modifies, instructing SwiftUI when to minimize the bar's contents. In the example it is applied to the NavigationStack's content as .toolbarMinimizeBehavior(.onScrollDown), governing the toolbar declared just above it.

  2. Choose a case to set the policy

    ToolbarMinimizeBehavior is a value you select rather than configure, so you pass one of its predefined cases to express the policy. The example passes .onScrollDown, which tells the toolbar to minimize as the reader scrolls downward through the content and restore itself otherwise.

  3. Pair it with a toolbar that has items to minimize

    The behavior only matters when there is a toolbar to act on, so it works in concert with a .toolbar block. Here the toolbar holds a single ToolbarItem(placement: .primaryAction) containing a Button("Compose", systemImage: "square.and.pencil") — that item is the content the behavior expands or condenses.

  4. Scope it to the navigation context

    Toolbar minimization is most meaningful inside a navigation container, where the bar and a title share the top edge with scrolling content. The modifier sits within the NavigationStack alongside .navigationTitle("Inbox"), so the minimize behavior coordinates with the navigation bar that hosts the toolbar.

Try it — Change .toolbarMinimizeBehavior(.onScrollDown) to .toolbarMinimizeBehavior(.never) and scroll the rows — the toolbar stays fully expanded instead of collapsing as you move down.

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.

ToolbarMinimizeBehavior.swift
struct ToolbarMinimizeBehaviorDemo: View {
    var body: some View {
        NavigationStack {
            ScrollView {
                ForEach(0..<20) { i in
                    Text("Row \(i + 1)")
                        .frame(maxWidth: .infinity, alignment: .leading)
                        .padding()
                }
            }
            .navigationTitle("Inbox")
            .toolbar {
                ToolbarItem(placement: .primaryAction) {
                    Button("Compose", systemImage: "square.and.pencil") {}
                }
            }
            .toolbarMinimizeBehavior(.onScrollDown)
        }
    }
}
Live preview
Row 1 Row 2 Row 3 Row 4 Row 5 Row 6 Row 7 Row 8 Row 9 Row 10 Row 11 Row 12 Row 13 Row 14 Row 15 Row 16 Row 17 Row 18 Row 19 Row 20 9:41 Inbox
Row 1 Row 2 Row 3 Row 4 Row 5 Row 6 Row 7 Row 8 Row 9 Row 10 Row 11 Row 12 Row 13 Row 14 Row 15 Row 16 Row 17 Row 18 Row 19 Row 20 9:41 Inbox
swift → lexer → parser → sema → uiir → canvas Open in Studio ↗
What's new in SwiftUI 27 →