TechnologiesSwiftUI

ToolbarOverflowMenu struct

iOSmacOStvOSwatchOSvisionOS✓ renders

The overflow menu of a toolbar.

How it works

ToolbarOverflowMenu collects a set of toolbar controls into a single, system-managed overflow menu, presented from a compact "more" affordance. Reach for it when a toolbar offers more actions than the available space can comfortably display, or when several related but secondary commands belong together rather than competing for prominence alongside primary controls. Rather than hand-placing every button, you declare the actions inside the menu and let SwiftUI surface them on demand, keeping the bar uncluttered while leaving every command reachable.

  1. Place ToolbarOverflowMenu inside the toolbar

    ToolbarOverflowMenu is a toolbar content type, so it lives inside the toolbar modifier rather than in the main view hierarchy. Here it is attached to the Text("Edit your document") view of a NavigationStack, which gives the menu a bar to render into and a navigationTitle("Notes") to sit alongside.

  2. Position it with ToolbarItemGroup and a placement

    Wrapping the menu in ToolbarItemGroup(placement: .primaryAction) tells SwiftUI where on the bar the overflow affordance should appear. The .primaryAction placement puts it in the leading edge of the trailing action area on most platforms, so the collapsed menu reads as the screen's main set of commands.

  3. Declare the actions in the trailing closure

    ToolbarOverflowMenu takes a content closure whose views become the menu's entries. The four Button items — "Share", "Duplicate", "Rename", and "Delete" — are listed in order, and SwiftUI lays them out as a vertical menu when the affordance is tapped, so you describe the commands without managing presentation.

  4. Give each entry a label and system image

    Each Button pairs a title with a systemImage, such as "square.and.arrow.up" for Share and "trash" for Delete, so the overflow menu renders consistent SF Symbol rows. The menu adopts the same labeling that buttons use elsewhere in the toolbar, keeping the iconography uniform whether an action is shown directly or tucked into the overflow.

  5. Signal intent with a button role

    Because menu entries are ordinary buttons, semantic roles flow through unchanged. Marking the last Button with role: .destructive lets ToolbarOverflowMenu style the Delete row distinctly — typically tinted red and grouped at the end — so a dangerous command stands apart from the routine ones.

Try it — Add a fifth Button("Export", systemImage: "arrow.up.doc") {} inside the ToolbarOverflowMenu closure and watch SwiftUI fold the new command into the same overflow menu without changing the bar's footprint.

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.

ToolbarOverflowMenu.swift
struct ToolbarOverflowMenuDemo: View {
    var body: some View {
        NavigationStack {
            Text("Edit your document")
                .padding()
                .navigationTitle("Notes")
                .toolbar {
                    ToolbarItemGroup(placement: .primaryAction) {
                        ToolbarOverflowMenu {
                            Button("Share", systemImage: "square.and.arrow.up") {}
                            Button("Duplicate", systemImage: "plus.square.on.square") {}
                            Button("Rename", systemImage: "pencil") {}
                            Button("Delete", systemImage: "trash", role: .destructive) {}
                        }
                    }
                }
        }
    }
}
Live preview
Edit your document 9:41 Notes
Edit your document 9:41 Notes
swift → lexer → parser → sema → uiir → canvas Open in Studio ↗
What's new in SwiftUI 27 →