Reputation: 51
I'm attempting to use the isAlternative property with an NSMenuItem with a custom view. It is not behaving as a standard NSMenuItem without a custom view. How do I get the standard modifier-key toggling behavior when using NSMenuItems with custom views?
Add a menu item. Add an additional menu item with .isAlternate == true and .keyEquivalentModifierMask = [ .option ] (or another appropriate modifier key).
When the menu is displayed, the first menu item is displayed. While the modifier key is held, the original menu item is replaced with the alternate menu item.
Add a menu item with a custom view. Add an additional menu item with a custom view with .isAlternate == true and .keyEquivalentModifierMask = [ .option ] (or another appropriate modifier key).
When the menu is display, instead of the standard toggling behavior, both the original and the alternate menu items are shown at all times.
Upvotes: 3
Views: 603
Reputation: 6070
NSMenuItem
isAlternate
to true
keyEquivalentModifierMask
let alternativeMenuItem = NSMenuItem("alternative", action: nil, keyEquivalent: "")
alternativeMenuItem.isAlternate = true
alternativeMenuItem.keyEquivalentModifierMask = [.option]
Upvotes: 2