TechnologiesSwiftUI

ToolbarTitleMenu struct

iOSmacOStvOSwatchOSvisionOSiOS 16.0+✓ renders

The title menu of a toolbar.

How it works

ToolbarTitleMenu is a toolbar item that attaches a pull-down menu directly to a navigation bar's title, surfacing actions that relate to the current view as a whole rather than to a single control. It gives people a familiar place to switch contexts or invoke document-level commands by tapping the title itself, which the system marks with a chevron to signal that it's interactive. Reach for it when the title names something the user can act on or navigate between — a document, a folder, an account — and you want those commands one tap away without crowding the toolbar with extra buttons.

  1. Place it inside a toolbar { } builder

    ToolbarTitleMenu is a toolbar content type, so it only takes effect when returned from a .toolbar modifier. In the example, the ToolbarTitleMenu { ... } lives in the .toolbar attached to the Text(folder) view, which lets SwiftUI bind the menu to that screen's navigation bar.

  2. Pair it with a navigation title

    The menu hangs off the title established by .navigationTitle, so the symbol needs a title to attach to. Here .navigationTitle(folder) supplies the text the chevron decorates, and because both the title and the menu read the same folder state, the displayed title is also the thing the menu controls.

  3. Provide the menu items as a content closure

    ToolbarTitleMenu takes a @ViewBuilder closure describing the menu's contents — typically a set of Buttons or other menu-friendly views. In the example the closure holds three Buttons ("Inbox", "Sent", "Archive"), each becoming a row in the pull-down.

  4. Drive state from the actions

    Because the items are ordinary views, their actions mutate app state like any other control. Each Button here assigns a new value to folder (for instance folder = "Sent"), and since the title is bound to @State private var folder, picking an item updates both the title and the body text at once.

Try it — Add a fourth Button("Spam") { folder = "Spam" } inside the ToolbarTitleMenu closure, then tap the navigation title to see the new option appear in the menu and rename the screen.

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.

ToolbarTitleMenu.swift
struct ToolbarTitleMenuDemo: View {
    @State private var folder = "Inbox"
    var body: some View {
        NavigationStack {
            Text(folder)
                .font(.title2)
                .padding()
                .navigationTitle(folder)
                .toolbar {
                    ToolbarTitleMenu {
                        Button("Inbox") { folder = "Inbox" }
                        Button("Sent") { folder = "Sent" }
                        Button("Archive") { folder = "Archive" }
                    }
                }
        }
    }
}
Live preview
Inb… 9:41
Inb… 9:41
swift → lexer → parser → sema → uiir → canvas Open in Studio ↗
What's new in SwiftUI 27 →