Instance Method

view(showsHighlight:_:)

Display a custom SwiftUI View instead of the title or attributed title.

Declaration

func view<Content>(showsHighlight: Bool = true, _ content: () -> Content) -> Self where Content : View

Discussion

The passed closure will only be called once.

Any views inside a menu item can use the \.menuItemIsHighlighted environment value to alter their appearance when highlighted.

By default, a selection material (NSVisualEffectView.Material.selection) will be drawn behind the view whenever menuItemIsHighlighted is true. You can disable this and handle highlighting yourself by passing showsHighlight: false

Example


MenuItem("\(server.name) is \(server.status.description)")
    .view {
        HStack {
            Circle()
                .fill(server.status.color)
                .frame(height: 8)
            Text(server.name)
            Spacer()
            Text(server.uptime)
        }
    }

See Also

Appearance