How it works
LabeledToolbarItemGroupContent is the content type SwiftUI produces when you give a ToolbarItemGroup both its set of controls and a label. It pairs a group of related toolbar items with a single representative label, so the system can present the items inline when there is room and collapse them behind that label — as an overflow menu or a compact control — when space is tight. Reach for it whenever several toolbar actions belong together conceptually and you want the platform to decide how much of the group to surface, rather than wiring up the collapse behavior yourself.
Build the group inside a toolbar with ToolbarItemGroup(placement:)
LabeledToolbarItemGroupContent is created for you when you construct a ToolbarItemGroup that takes a label. You declare it in a
.toolbarclosure and give it a placement that tells SwiftUI where the group belongs; hereToolbarItemGroup(placement: .primaryAction)anchors the formatting controls in the leading action area.Supply the grouped controls as the content closure
The first trailing closure holds the items that travel together. Each becomes part of the same labeled group, so they collapse and expand as a unit. In the example the three
Button("Bold", systemImage: "bold"),Button("Italic", systemImage: "italic"), andButton("Underline", systemImage: "underline")controls form one cohesive formatting cluster.Provide the representative label with the label: closure
The
label:closure is what makes this a labeled group rather than a plain ToolbarItemGroup — it is the single title and glyph that stands in for the whole cluster when SwiftUI collapses it. TheLabel("Format", systemImage: "textformat")here gives the group a name and icon, so the collapsed presentation reads as "Format" with the textformat symbol and expands to reveal the individual buttons.Let placement and available space drive presentation
Because the group carries its own label, SwiftUI can choose between showing the items inline and folding them under the label based on the current layout. You don't toggle this; the LabeledToolbarItemGroupContent the initializer returns is the value the toolbar uses to manage that adaptive behavior across size classes and window widths.
Button("Strikethrough", systemImage: "strikethrough") {} to the content closure and narrow the window — watch the labeled group collapse the buttons under the Label("Format", systemImage: "textformat") instead of laying them all out inline.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.
struct LabeledToolbarItemGroupContentDemo: View {
var body: some View {
NavigationStack {
Text("Edit your document")
.padding()
.toolbar {
ToolbarItemGroup(placement: .primaryAction) {
Button("Bold", systemImage: "bold") {}
Button("Italic", systemImage: "italic") {}
Button("Underline", systemImage: "underline") {}
} label: {
Label("Format", systemImage: "textformat")
}
}
}
}
}