TechnologiesSwiftUI

DefaultMenuStyle struct

iOSmacOStvOSwatchOSvisionOS✓ renders

The default menu style, based on the menu's context.

How it works

DefaultMenuStyle is the menu style SwiftUI applies to a Menu when you don't specify one of your own. It resolves to the platform-appropriate presentation for the current context — a pull-down button on iOS and macOS, adapting its chrome, label treatment, and item layout to match system conventions. Reach for it when you want a Menu to look and behave like a standard system menu, or when you need to reset a view hierarchy back to the default presentation after a custom style has been applied higher up the tree.

  1. Let a Menu adopt the default presentation

    A Menu shows a label that, when activated, presents its contents as a list of actions. Without an explicit style, the menu is rendered with DefaultMenuStyle, so the Menu("Options") here already displays as a standard system pull-down with no extra configuration.

  2. Select the style with menuStyle(_:)

    The menuStyle(_:) modifier sets the style for menus within a view. Passing .automatic requests the default style, which is exactly what DefaultMenuStyle provides — the .menuStyle(.automatic) call states the default explicitly and is equivalent to applying no style at all.

  3. Use the .automatic shorthand

    .automatic is the MenuStyle value that resolves to DefaultMenuStyle. It exists so you can write .menuStyle(.automatic) to opt back into the system default — useful when an ancestor view set a custom menu style and you want a particular subtree to return to standard appearance.

  4. Lay out the menu items the default style renders

    DefaultMenuStyle arranges whatever controls you place in the menu's content closure. Here the Button("Rename", systemImage:) rows, the Divider() that groups them, and the destructive Button("Delete", role: .destructive) are each presented in the standard menu metrics, with the destructive role drawn in the system's emphasis color.

Try it — Change .menuStyle(.automatic) to .menuStyle(.button) to see how the same Menu departs from the default presentation, then switch it back to confirm DefaultMenuStyle restores the standard pull-down.

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.

DefaultMenuStyle.swift
struct DefaultMenuStyleDemo: View {
    var body: some View {
        Menu("Options") {
            Button("Rename", systemImage: "pencil") {}
            Button("Duplicate", systemImage: "plus.square.on.square") {}
            Divider()
            Button("Delete", systemImage: "trash", role: .destructive) {}
        }
        .menuStyle(.automatic)
        .padding()
    }
}
Live preview
Options
Options
swift → lexer → parser → sema → uiir → canvas Open in Studio ↗
What's new in SwiftUI 27 →