6

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?

iHunter
  • 6,205
  • 3
  • 38
  • 56

2 Answers2

4

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

iHunter
  • 6,205
  • 3
  • 38
  • 56
  • Odd. I tried that as well but it resulted in a border-less button. "Momentary Push In" also caused the triangle to be facing right instead of down. – omz Dec 21 '11 at 13:14
  • My solution obviously works on Lion with XCode 4.2. What OS and XCode version are you using? – iHunter Dec 21 '11 at 13:18
  • Same. I just did my initial experiment with the old version of IB because I find it a bit more convenient, but I tried your solution in Xcode 4.2 on Lion. – omz Dec 21 '11 at 13:21
  • Anyway, good if it works for you. Perhaps I accidentally changed some other parameter. – omz Dec 21 '11 at 13:23
  • @omz Are you using **Disclosure Triangle** or **Disclosure** (Style)? – paulmelnikow Jun 14 '12 at 18:41
1

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.

omz
  • 53,243
  • 5
  • 129
  • 141