How can I create a NSPopUpButton that uses a fixed Image, and no arrows?

d11wtq picture d11wtq · Dec 7, 2010 · Viewed 8.2k times · Source

I'm trying to get NSPopUpButton to render like a standard NSButton with only an image set, but not having any luck.

Much like the "+" button in Mail.app:

Not clicked Clicked

I assume they did this with NSPopUpButton. The obvious thing I've tried is:

NSMenuItem *imageItem = [[[NSMenuItem alloc] init] autorelease];
[imageItem setImage:[NSImage imageNamed:NSImageNameAddTemplate]];

[[popUpButton cell] setUsesItemFromMenu:NO];
[[popUpButton cell] setMenuItem:imageItem];
[[popUpButton cell] setImagePosition:NSImageOnly];

This doesn't show the image however, instead it just shows a pair of arrows (I suspect they're drawn over where the image would be). Calling [popUpButton setImage:...] also does nothing.

Is there a documented way to do this, or does it come down to some custom subclassing?

Answer

Tomer picture Tomer · Nov 12, 2013

To prevent the button from displaying the arrow:

[popupButton.cell setArrowPosition:NSPopUpNoArrow];