How it works
AutomaticControlGroupStyle is the default style applied to a ControlGroup, the type SwiftUI uses whenever you don't explicitly choose another control group style. Rather than fixing a single appearance, it lets the system pick the presentation that's most appropriate for the context in which the control group appears — a horizontal row of controls in a toolbar, a menu when space is constrained, and so on. Reach for it when you want a group of related controls to look and behave like a native, platform-appropriate cluster without dictating the layout yourself, and you get it for free simply by placing controls in a ControlGroup.
Group related controls in a
ControlGroupA
ControlGroupcollects several controls that act on a common subject so SwiftUI can present them as one cohesive unit. Here the group's content closure holds three related actions — theButton("Cut", systemImage: "scissors"),Button("Copy", ...), andButton("Paste", ...)controls — whichAutomaticControlGroupStylewill arrange together.Apply the style with
.controlGroupStyle(.automatic)The
controlGroupStyle(_:)modifier sets the style for a control group and the groups within it. Passing.automaticselectsAutomaticControlGroupStyle, the system-chosen default; writing it explicitly here documents that you're deferring the presentation decision to SwiftUI rather than overriding it.Let context drive the presentation
Because
AutomaticControlGroupStyleresolves to a context-appropriate appearance, the sameControlGroupadapts to where it lives — inline in this view'sbody, but rendered differently if it were placed in a toolbar or menu. You write the controls once and the style adapts the layout for you.Use
.automaticas the baseline to swap fromSince
.automaticis the implicit default, its main role in code is as an explicit baseline you can replace. Changing the argument ofcontrolGroupStyle(.automatic)to another style is all it takes to move from the system's choice to a specific presentation, while theButtoncontent stays untouched.
.controlGroupStyle(.automatic) to .controlGroupStyle(.navigation) and watch the same Cut/Copy/Paste buttons re-arrange into a different presentation, revealing what the automatic style was choosing for you.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 AutomaticControlGroupStyleDemo: View {
var body: some View {
ControlGroup {
Button("Cut", systemImage: "scissors") {}
Button("Copy", systemImage: "doc.on.doc") {}
Button("Paste", systemImage: "doc.on.clipboard") {}
}
.controlGroupStyle(.automatic)
.padding()
}
}