You’re previewing Ry’s Cocoa TutorialUI Components

Menus

Cocoa provides three types of built-in menus. The most familiar is probably the application menu bar, which defines the File, Edit, and other menus at the top of the screen. Contextual menus let the user alter a particular UI component by control-clicking it. Finally, pop-up menus display a list of options for the user to choose from, much like a Combo Box.

All of these menus are powered by the NSMenu and NSMenuItem classes. NSMenu is a container for a list of NSMenuItem objects, and each NSMenuItem represents a single item in the menu. You can nest menus by providing a submenu (represented as another NSMenu object) to an NSMenuItem instance.

Structure of a typical File menu

In this chapter, we’ll take an in-depth look at the organization of the application menu bar so that you’ll understand how to customize it for your own projects. We’ll also explore basic NSMenuItem configuration, as well as how to adapt all these skills to contextual menus and pop-up menus.

Sorry, this is the end of the preview. To read the rest of this chapter, you’ll need to purchase Ry’s Cocoa Tutorial.

Mailing List

Sign up for my low-volume mailing list to find out when new content is released. Next up is a comprehensive Swift tutorial planned for late January.

You’ll only receive emails when new tutorials are released, and your contact information will never be shared with third parties. Click here to unsubscribe.