Search code examples
objective-cmacosappkitnsbuttonnsmenu

Disclosure button displaying a menu


Please give me an advice how to implement this kind of disclosure button as on my screenshot - a disclosure "arrow down" button displaying a menu on click:

What do I want

I've tried two approaches, using NSPopupButton and NSButton with disclosure style and manual menu displaying:

  • NSPopupButton keeps displaying default value text and can't be resized in Interface Builder to a narrow size.

    NSPopupButton

  • NSButton displays a menu, but it's obviously misplaced to the point where I click the button, not at the bottom edge. I'm using the following code:

    - (IBAction)handleShowMenu:(id)sender
    {
        [NSMenu popUpContextMenu:profileMenu
                       withEvent:[NSApp currentEvent]
                         forView:sender];
    }
    

    NSButton with menu

So what's the right way to display such a menu?


Solution

  • I've managed with it! The correct setup is to use NSPopupButton with "No Arrow" and "Disclosure" bezel style, "Momentary Push In" type.