Attaches a contextual menu to the view.
SDKs
- iOS 13.0+
- macOS 10.15+
- Mac Catalyst 13.0+
- watchOS 6.0+
- Xcode 11.0+
Framework
- Swift
UI
Declaration
func contextMenu<MenuItems>(@View Builder menuItems: () -> MenuItems) -> some View where MenuItems : View
Return Value
A view that adds a contextual menu to this view.
Discussion
Use contextual menus to add actions that change depending on the user’s current focus and task.
The following example creates text with a contextual menu:
Text("Control Click Me")
.contextMenu {
Button(action: { print("added") } ) { Text("Add") }
Button(action: { print("removed") } ) { Text("Remove") }
}