Structure¶
Menu¶
A control for presenting a menu of actions.¶
Declaration¶
struct Menu<Label, Content> : View where Label : View, Content : View
Overview¶
A menu is created from a view builder of different views. Each acceptable view will be shown as a different row in the menu. The canonical view for using in a menu is Button, but these views also work: Menu, Text, Button, Link, Label, Divider, and Image.
There are 3 different initializers, one for each of the different label types:
The following example presents a menu of three buttons and a submenu, which contains two buttons of its own.
struct MenuView: View {
var body: some View {
Menu("Actions") {
Button("Duplicate", action: { print("‼️") })
Button("Delete…", action: { print("🗑") })
Menu("Copy") {
Button("Copy", action: { print("📑") })
Button("Copy Formatted", action: { print("🔤") })
}
}
}
}

You can create the menu's title with a LocalizedStringKey, as seen in the previous example, or with a ViewBuilder that creates multiple views, such as an image and a text view:
struct MenuView: View {
var body: some View {
Menu {
Button("Open in Preview", action: { })
Button("Save as PDF", action: { })
} label: {
Image(systemName: "doc")
Text("PDF")
}
}
}

Styling Menus¶
Use the menuStyle(_:) modifier to change the style of all menus in a view. See the MenuStyle page for more on the types of styles available, as well as how to create your own style.
struct MenuView: View {
var body: some View {
Menu("Editing") {
Button("Set In Point", action: { })
Button("Set Out Point", action: { })
}
.menuStyle(DefaultMenuStyle())
}
}

Availability¶
iOS 14.0+
macOS 11.0+
Topics¶
Instance Property¶
body The content and behavior of the view.
Initializer¶
init(_:) Creates a menu based on a style configuration.
init(_:content:) Creates a menu with a localized string key label.
init(_:content:) Creates a menu with a string label.
init(content:label:) Creates a menu with a view label.
Type Alias¶
Body The type of view representing the body of this view.