TechnologiesSwiftUIControls and Style Configurations

MenuStyleConfiguration struct

iOSmacOStvOSwatchOSvisionOS✓ renders

A configuration of a menu.

How it works

MenuStyleConfiguration carries the resolved properties of a menu — its label and its contents — to a custom menu style at the moment SwiftUI is about to render it. You don't create this type yourself; SwiftUI builds an instance and hands it to your style's makeBody(configuration:) method, where it represents the menu that the system wants drawn. Reach for it whenever the built-in menu styles aren't enough and you want to define your own reusable appearance for menus by conforming to MenuStyle, while leaving the menu's behavior and interaction to the framework.

  1. Conform to MenuStyle and receive the Configuration

    A custom menu style is a type that conforms to MenuStyle and implements makeBody(configuration:). The configuration parameter is a MenuStyleConfiguration value describing the menu to render. In the example, BorderedMenuStyle conforms to MenuStyle, and its makeBody(configuration:) signature receives configuration as the typealiased Configuration (which is MenuStyleConfiguration).

  2. Rebuild the menu with Menu(_:)

    Rather than exposing each property individually, you typically pass the whole configuration to the Menu(_:) initializer that accepts a MenuStyleConfiguration. This reconstructs the system menu — preserving its label and the actions inside — so you can wrap it in your own visuals. The example writes Menu(configuration) to recreate the menu before styling it.

  3. Apply your appearance around the reconstructed menu

    Once you have the menu back from Menu(configuration), you decorate it with ordinary view modifiers to define the style's look. Here the menu is given padding(8), a tinted background(Color.blue.opacity(0.15)), and a clipShape(RoundedRectangle(cornerRadius: 8)) — the framing that makes BorderedMenuStyle distinct without touching what the menu does.

  4. Install the style with menuStyle(_:)

    A MenuStyle takes effect only when you attach it to a menu (or an enclosing view) with the menuStyle(_:) modifier, which is where SwiftUI produces the MenuStyleConfiguration and invokes your makeBody. The example applies .menuStyle(BorderedMenuStyle()) to the Menu("Options") that holds the Rename, Duplicate, and Delete buttons.

Try it — Change the background in makeBody from Color.blue.opacity(0.15) to Color.red.opacity(0.15) to see your MenuStyleConfiguration-driven style repaint the same menu without altering its Rename, Duplicate, or Delete actions.

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.

MenuStyleConfiguration.swift
struct MenuStyleConfigurationDemo: View {
    struct BorderedMenuStyle: MenuStyle {
        func makeBody(configuration: Configuration) -> some View {
            Menu(configuration)
                .padding(8)
                .background(Color.blue.opacity(0.15))
                .clipShape(RoundedRectangle(cornerRadius: 8))
        }
    }

    var body: some View {
        Menu("Options") {
            Button("Rename") {}
            Button("Duplicate") {}
            Button("Delete", role: .destructive) {}
        }
        .menuStyle(BorderedMenuStyle())
        .padding()
    }
}
Live preview
Options
Options
swift → lexer → parser → sema → uiir → canvas Open in Studio ↗
What's new in SwiftUI 27 →