How to configure ContextMenu buttons for delete and disabled in SwiftUI?

All of the asked situations are now supported in iOS 15

Destructive: (works from iOS 15)

Set .destructive as the role argument of the button:

Button(role: .destructive) { // 👈 This argument
    // delete something
} label: {
    Label("Delete", systemImage: "trash")
}

Delete Demo


Disabled: (works from iOS 14.2)

Add .disabled modifier to the button.

Button {
    // call someone
} label: {
    Label("Call", systemImage: "phone")
}.disabled(true) // 👈 This modifier

Disabled Demo


Divider: (works from iOS 14)

Use a Divider() view directly.

Divider Demo


Full Demo:

Demo
⚠️ Remember! Do not use image instead of systemImage for showing an SFSymbol on the button!

Leave a Comment