TechnologiesSwiftUI

DefaultGroupBoxStyle struct

iOSmacOStvOSwatchOSvisionOS✓ renders

The default style for group box views.

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.

  1. 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.

  2. 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 enclosing GroupBox("Account").

  3. Reference it through the .automatic shorthand

    Rather than constructing the style directly, you use the static automatic accessor exposed on GroupBoxStyle, which vends a DefaultGroupBoxStyle instance. Passing .automatic to groupBoxStyle is the canonical way to ask for the system's standard box appearance, and it is exactly equivalent to writing .groupBoxStyle(DefaultGroupBoxStyle()).

  4. 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") and Text("Plan: Pro") rows, supplying the rounded background and padding so you don't size or inset the panel by hand.

Try it — Remove the .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.

DefaultGroupBoxStyle.swift
struct DefaultGroupBoxStyleDemo: View {
    var body: some View {
        GroupBox("Account") {
            Text("Signed in as toprak")
            Text("Plan: Pro")
                .foregroundStyle(.secondary)
        }
        .groupBoxStyle(.automatic)
        .padding()
    }
}
Live preview
Account Signed in as toprak Plan: Pro
Account Signed in as toprak Plan: Pro
swift → lexer → parser → sema → uiir → canvas Open in Studio ↗
What's new in SwiftUI 27 →