Search code examples
objective-cmacoscocoansmenuitemnsmenu

How to create a custom NSMenuItem


Well, I have quite a basic question which I can't seem to find an answer to. I followed this guide to create a StatusBar menu, which works great... However, I would like to add a custom NSMenuItem containing custom stuff. As example such as the sound slider, or the switch user account row ect.

How can I do that?

Even links to tutorials are welcome.


Solution

  • In most cases, you'll create a custom view containing the slider or whatever else you want to appear in the menu item. Then you call setView: on the NSMenuItem in question.

    For more details, check this article from Apple's documentation: https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/MenuList/Articles/ViewsInMenuItems.html