How it works
ToolbarLabelStyle describes how the labels of toolbar items render — whether each item shows its title, its icon, or both. SwiftUI normally chooses a presentation for toolbar labels based on the platform, placement, and available space, but that automatic behavior isn't always what you want for a given bar. Reach for ToolbarLabelStyle when you need to override that choice and pin the labels in a toolbar to a consistent appearance, so a row of actions reads uniformly rather than mixing icon-only and titled buttons.
Apply the style with toolbarLabelStyle(_:)
You don't construct a ToolbarLabelStyle directly; you set one on a view hierarchy with the
toolbarLabelStyle(_:)modifier, which takes a style value and applies it to every toolbar label below it. In the example the modifier is attached to the navigation content as.toolbarLabelStyle(.titleAndIcon), so both toolbar buttons adopt that presentation.Pick a presentation: .titleAndIcon, .iconOnly, .titleOnly, .automatic
ToolbarLabelStyle exposes its presentations as static members you pass to the modifier.
.titleAndIconshows each label's text and symbol together,.iconOnlyand.titleOnlykeep just one, and.automaticdefers to SwiftUI's default. The example chooses.titleAndIconto guarantee the action labels surface their words, not just glyphs.Drive it from each item's Label
The style governs how SwiftUI lays out a
Label's title andsystemImageonce that label lands in a toolbar. HereLabel("Add", systemImage: "plus")andLabel("Share", systemImage: "square.and.arrow.up")each carry both pieces, so the chosen ToolbarLabelStyle has both a title and an icon to compose — a label with only one would still respect the style but render only what it has.Scope it to the toolbar's items
Because the modifier flows down the environment, a single
toolbarLabelStyleon a container restyles all theToolbarItemlabels inside the enclosing.toolbar { }at once. TheToolbarItem(placement: .primaryAction)andToolbarItem(placement: .secondaryAction)buttons both inherit.titleAndIconwithout being styled individually.
.toolbarLabelStyle(.titleAndIcon) to .toolbarLabelStyle(.iconOnly) and watch the "Add" and "Share" text drop away so only the plus and square.and.arrow.up symbols remain.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 ToolbarLabelStyleDemo: View {
var body: some View {
NavigationStack {
Text("Editing document")
.padding()
.navigationTitle("Notes")
.toolbar {
ToolbarItem(placement: .primaryAction) {
Button {
} label: {
Label("Add", systemImage: "plus")
}
}
ToolbarItem(placement: .secondaryAction) {
Button {
} label: {
Label("Share", systemImage: "square.and.arrow.up")
}
}
}
.toolbarLabelStyle(.titleAndIcon)
}
}
}