How it works
A ControlGroup displays semantically related controls as a single, visually unified unit. SwiftUI renders the grouped controls with a shared background and platform-appropriate spacing, so a cluster of buttons reads as one coordinated control rather than a loose row of separate ones. Reach for it when you have a handful of actions that belong together — zoom in and out, a set of toolbar commands, segmented operations — and you want the system to lay them out and style them consistently.
Group controls in the content closure
The first trailing closure holds the controls that belong to the group; SwiftUI gathers them and presents them as one unit. Here the closure contains two
Buttonviews, an"Increase"button and a"Decrease"button, whichControlGrouparranges together with shared chrome instead of as independent buttons.Describe each action with Label
Inside the grouped buttons,
Labelpairs a title with an SF Symbol so each control carries both text and an icon. The example usesLabel("Increase", systemImage: "plus")andLabel("Decrease", systemImage: "minus");ControlGroupreads these labels to size and render the controls uniformly, and platforms may collapse them to icon-only when space is tight.Supply a group label with the label closure
The second closure, marked
label:, names the group as a whole. ProvidingText("Zoom")gives the cluster an accessible title and lets contexts such as toolbars or menus show a heading or representative label for the collapsed group, distinct from the individual control labels.Apply modifiers to the whole group
Because
ControlGroupis itself aView, modifiers attach to the unit and affect it as a whole rather than the inner controls. The.padding()here insets the entire group, so the shared layout and spacingControlGroupprovides stays intact while you position the cluster withinbody.
Button with Label("Reset", systemImage: "arrow.counterclockwise") inside the content closure to watch ControlGroup absorb it into the same unified cluster with consistent spacing and styling.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 ControlGroupDemo: View {
var body: some View {
ControlGroup {
Button {
} label: {
Label("Increase", systemImage: "plus")
}
Button {
} label: {
Label("Decrease", systemImage: "minus")
}
} label: {
Text("Zoom")
}
.padding()
}
}