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.
Let a Menu adopt the default presentation
A
Menushows a label that, when activated, presents its contents as a list of actions. Without an explicit style, the menu is rendered with DefaultMenuStyle, so theMenu("Options")here already displays as a standard system pull-down with no extra configuration.Select the style with menuStyle(_:)
The
menuStyle(_:)modifier sets the style for menus within a view. Passing.automaticrequests 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.Use the .automatic shorthand
.automaticis 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.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, theDivider()that groups them, and the destructiveButton("Delete", role: .destructive)are each presented in the standard menu metrics, with the destructive role drawn in the system's emphasis color.
.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.
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()
}
}