TechnologiesSwiftUI

ToolbarItemGroup struct

iOSmacOStvOSwatchOSvisionOSiOS 14.0+✓ renders

A model that represents a group of `ToolbarItem`s which can be placed in

How it works

ToolbarItemGroup is a toolbar content type that places several related controls into a single shared region of a toolbar, all governed by one placement. Reach for it when you have a cluster of items — formatting buttons, view-mode toggles, a set of actions — that logically belong together and should land in the same spot. Where a ToolbarItem positions one view, ToolbarItemGroup positions many at once, letting the system lay them out and adapt them as a unit. You supply it inside a .toolbar closure, the same place every other toolbar content lives.

  1. Add toolbar content with the .toolbar modifier

    Toolbar content is declared by attaching .toolbar to a view inside a navigation container. In the example the modifier hangs off the Text("Document") view within a NavigationStack, and its closure is where ToolbarItemGroup is placed. The group only takes effect because it lives in this toolbar-content context.

  2. Group related controls with ToolbarItemGroup

    ToolbarItemGroup wraps a @ViewBuilder of toolbar views, so you list the controls directly in its trailing closure and they are treated as one cohesive set. Here the three formatting Buttons — bold, italic, and underline — are declared back-to-back inside the group, sharing its layout and placement instead of each needing its own ToolbarItem.

  3. Position the whole group with placement

    The placement parameter takes a ToolbarItemPlacement that decides where the entire group is shown, so every control inside moves together. In the example placement: .bottomBar sends all three buttons to the bottom toolbar at once; changing this single value relocates the whole cluster rather than any one button.

  4. Supply the controls as ordinary toolbar views

    The contents of a ToolbarItemGroup are normal SwiftUI views, typically interactive controls. The example uses Button views whose label is an Image(systemName:)"bold", "italic", and "underline" — and the group preserves their declared order, keeping the icons adjacent and consistently spaced as a toolbar segment.

Try it — Change placement: .bottomBar to .navigationBarTrailing (or .primaryAction) and watch all three buttons move to the top trailing edge together, confirming that the group's single placement controls every item it contains.

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.

ToolbarItemGroup.swift
struct ToolbarItemGroupDemo: View {
    var body: some View {
        NavigationStack {
            Text("Document")
                .padding()
                .navigationTitle("Editor")
                .toolbar {
                    ToolbarItemGroup(placement: .bottomBar) {
                        Button {
                        } label: {
                            Image(systemName: "bold")
                        }
                        Button {
                        } label: {
                            Image(systemName: "italic")
                        }
                        Button {
                        } label: {
                            Image(systemName: "underline")
                        }
                    }
                }
        }
    }
}
Live preview
Document 9:41 Editor
Document 9:41 Editor
swift → lexer → parser → sema → uiir → canvas Open in Studio ↗
What's new in SwiftUI 27 →