Generic Instance Method

contextMenu(menuItems:)

Adds a contextual menu to this view.

Declaration

func contextMenu<MenuItems>(@ViewBuilder 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") }
}

See Also

Configuring Context Menu Views

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

Attaches a ContextMenu and its children to self.