Cocoa: drop down menu buttons

Apple, Cocoa, General

In Cocoa, it is pretty easy to use an NSButton that creates a drop down menu. One of the key-tricks to making it appear to be an NSPopUpButton is to set the [NSCell sendActionOn:]. Generally, menus are displayed on mouse down, not up. Normally, the action for a button is sent on mouse up. To get around this, you can simply access the cell of your button and tell it to send the action on mouse down:

[[mybutton cell] sendActionOn:NSLeftMouseDownMask];

Cool!



Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments

Subscribe to new posts:

You'll get an email whenever a I publish a new post to my blog and nothing more. -- Corbin

As an Amazon Associate I earn from qualifying purchases.

(c) 2008-2024 Corbin Dunn

Privacy Policy

Subscribe to RSS feeds for entries.

65 queries. 0.277 seconds.

Log in