How it works
DefaultGroupBoxStyle is the group box style that SwiftUI applies automatically whenever you place a GroupBox without specifying a style of your own. It renders the box's content inside the platform's standard rounded background, with the appropriate insets, label treatment, and material for the current context, so your grouped controls look native without any extra configuration. Reach for it when you want the conventional appearance and you need to name that appearance explicitly — for example, to restore the system default after another style was applied higher up the view hierarchy.
Conform to GroupBoxStyle
DefaultGroupBoxStyle adopts the GroupBoxStyle protocol, which is the contract every group box style implements: a makeBody(configuration:) method that receives the box's label and content and returns the styled view. Because the default style already conforms, you never write that method yourself — you simply hand the style to a GroupBox, as the
GroupBox("Account")here does implicitly.Select it with groupBoxStyle(_:)
Apply a group box style by attaching the groupBoxStyle(_:) modifier to a GroupBox or to any container of group boxes. The modifier takes a GroupBoxStyle value and sets it for the box and its descendants. In the example,
.groupBoxStyle(.automatic)resolves to DefaultGroupBoxStyle for the enclosingGroupBox("Account").Reference it through the .automatic shorthand
Rather than constructing the style directly, you use the static
automaticaccessor exposed on GroupBoxStyle, which vends a DefaultGroupBoxStyle instance. Passing.automatictogroupBoxStyleis the canonical way to ask for the system's standard box appearance, and it is exactly equivalent to writing.groupBoxStyle(DefaultGroupBoxStyle()).Let it lay out the label and content
Once selected, DefaultGroupBoxStyle takes the GroupBox's title and body and arranges them in the standard layout — the label sits above a panel that wraps the content. Here it positions the "Account" title over the
Text("Signed in as toprak")andText("Plan: Pro")rows, supplying the rounded background and padding so you don't size or inset the panel by hand.
.groupBoxStyle(.automatic) line entirely and confirm the GroupBox looks identical — proof that DefaultGroupBoxStyle is the style SwiftUI was already using.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 DefaultGroupBoxStyleDemo: View {
var body: some View {
GroupBox("Account") {
Text("Signed in as toprak")
Text("Plan: Pro")
.foregroundStyle(.secondary)
}
.groupBoxStyle(.automatic)
.padding()
}
}