Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 230
iHunter Avatar asked Dec 21 '11 12:12

iHunter


2 Answers

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

like image 74
iHunter Avatar answered Sep 30 '22 16:09

iHunter


Changing the bezel style of your popup button to "Textured" and the arrow to "Center" will give you the appearance of your first screenshot. If you don't want the title of the selected item to appear, you also need to set the "Position" to "image only" (the white square).

Edit: I tried this in IB 3 and only simulated the interface. It seems that the "Textured" style looks different in Xcode 4. "Round Textured" is close, but it doesn't center the triangle horizontally.

like image 31
omz Avatar answered Sep 30 '22 17:09

omz