Generic Instance Method


Attaches a contextual menu to the view.


func contextMenu<MenuItems>(@ViewBuilder menuItems: () -> MenuItems) -> some View where MenuItems : View

Return Value

A view that adds a contextual menu to this view.


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") }

See Also

Configuring Context Menu Views

func contextMenu<MenuItems>(ContextMenu<MenuItems>?) -> View

Attaches a contextual menu and its children to the view.