TechnologiesSwiftUI

MenuControlGroupStyle struct

iOSmacOStvOSwatchOSvisionOS✓ renders

A control group style that presents its content as a menu when the user

How it works

MenuControlGroupStyle is a control group style that collapses the controls of a ControlGroup into a single menu, presenting the grouped actions behind one button that expands on demand rather than laying them out inline. Reach for it when a ControlGroup holds several related commands but you want them tucked away to conserve space — for example in a toolbar or a compact region where a row of buttons would crowd the layout. You apply it through the controlGroupStyle(_:) modifier using the .menu shorthand, and SwiftUI handles building the menu affordance and its presentation for you.

  1. Group the commands with ControlGroup

    MenuControlGroupStyle styles the contents of a ControlGroup, so the controls you want to consolidate go inside its closure. In the example, three Button controls labeled Cut, Copy, and Paste are declared as the group's children; the style determines how that set is displayed, not which controls belong to it.

  2. Apply the style with controlGroupStyle(.menu)

    The controlGroupStyle(_:) view modifier sets the style for control groups in its subtree. Passing .menu selects MenuControlGroupStyle, the static accessor that resolves to this style, which is why the example writes .controlGroupStyle(.menu) rather than constructing the type directly.

  3. Let the style fold the controls into one menu

    Under MenuControlGroupStyle, the grouped controls no longer render as side-by-side buttons; instead they become entries in a menu reached through a single trigger. The Label of each ButtonLabel("Cut", systemImage: "scissors") and its siblings — supplies the title and systemImage for the corresponding menu item.

  4. Rely on conformance to ControlGroupStyle

    MenuControlGroupStyle conforms to ControlGroupStyle, the protocol that defines how a control group's body is built from its configuration. That conformance is what makes it a valid argument to controlGroupStyle(_:), and it lets you swap to other built-in styles such as .automatic or .navigation without changing the ControlGroup itself.

Try it — Change .controlGroupStyle(.menu) to .controlGroupStyle(.automatic) and watch the Cut, Copy, and Paste buttons spread out inline instead of folding behind a single menu trigger.

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.

MenuControlGroupStyle.swift
struct MenuControlGroupStyleDemo: View {
    var body: some View {
        ControlGroup {
            Button {
            } label: {
                Label("Cut", systemImage: "scissors")
            }
            Button {
            } label: {
                Label("Copy", systemImage: "doc.on.doc")
            }
            Button {
            } label: {
                Label("Paste", systemImage: "doc.on.clipboard")
            }
        }
        .controlGroupStyle(.menu)
        .padding()
    }
}
Live preview
Cut Copy Paste
Cut Copy Paste
swift → lexer → parser → sema → uiir → canvas Open in Studio ↗
What's new in SwiftUI 27 →