I need to make a popup or pull down menu in Cocoa that will contain either an image or an image with text as the representation of the item. Can anyone suggest a way I could do this programatically?
+11
A:
Any sort of menu in Cocoa, whether it's in the menubar, part of an NSPopUpButton
, or a combobox, uses NSMenu
to display its menu. The NSMenu
displays a list of NSMenuItem
s. Each NSMenuItem
has a -[NSMenuItem setImage:]
method. Have you tried that?
Dave DeLong
2009-09-23 19:14:49
Wow, I had actually just made a popup menu so this was quite trivial once I knew that I could just set the image like that, thanks!
Mike2012
2009-09-23 19:21:17
As of 10.5, you can also use `-[NSMenuItem setView:]` to use any kind of NSView in a menu item. For example, sliders, steppers, etc. Don't get carried away with it, but notice how the Help menu in 10.5+ starts with a Spotlight-like search box...
Quinn Taylor
2009-09-23 21:12:55