Class

NSMenu

An object that manages an app’s menus.

Declaration

@interface NSMenu : NSObject

Topics

Managing the Menu Bar

+ menuBarVisible

Returns a Boolean value that indicates whether the menu bar is visible.

+ setMenuBarVisible:

Sets whether the menu bar is visible and selectable by the user.

menuBarHeight

The menu bar height for the main menu in pixels.

Creating an NSMenu Object

- initWithTitle:

Initializes and returns a menu having the specified title and with autoenabling of menu items turned on.

Adding and Removing Menu Items

- insertItem:atIndex:

Inserts a menu item into the menu at a specific location.

- insertItemWithTitle:action:keyEquivalent:atIndex:

Creates and adds a menu item at a specified location in the menu.

- addItem:

Adds a menu item to the end of the menu.

- addItemWithTitle:action:keyEquivalent:

Creates a new menu item and adds it to the end of the menu.

- removeItem:

Removes a menu item from the menu.

- removeItemAtIndex:

Removes the menu item at a specified location in the menu.

- itemChanged:

Invoked when a menu item is modified visually (for example, its title changes).

- removeAllItems

Removes all the menu items in the menu.

Finding Menu Items

- itemWithTag:

Returns the first menu item in the menu with the specified tag.

- itemWithTitle:

Returns the first menu item in the menu with a specified title.

- itemAtIndex:

Returns the menu item at a specific location of the menu.

numberOfItems

The number of menu items in the menu, including separator items.

itemArray

An array containing the menu items in the menu.

Finding Indices of Menu Items

- indexOfItem:

Returns the index identifying the location of a specified menu item in the menu.

- indexOfItemWithTitle:

Returns the index of the first menu item in the menu that has a specified title.

- indexOfItemWithTag:

Returns the index of the first menu item in the menu identified by a tag.

- indexOfItemWithTarget:andAction:

Returns the index of the first menu item in the menu that has a specified action and target.

- indexOfItemWithRepresentedObject:

Returns the index of the first menu item in the menu that has a given represented object.

- indexOfItemWithSubmenu:

Returns the index of the menu item in the menu with the given submenu.

Managing Submenus

- setSubmenu:forItem:

Assigns a menu to be a submenu of the menu controlled by a given menu item.

- submenuAction:

The action method assigned to menu items that open submenus.

- attachedMenu

Returns the menu currently attached to the menu.

Deprecated
- isAttached

Returns a Boolean value that indicates whether the menu is currently attached to another menu.

Deprecated
- locationForSubmenu:

Returns the location in screen coordinates where the given submenu is displayed when opened as a submenu of the menu.

Deprecated
supermenu

The parent menu that contains the menu as a submenu.

tornOff

Indicates whether the menu is offscreen or attached to another menu (or if it’s the main menu).

Deprecated

Enabling and Disabling Menu Items

autoenablesItems

Indicates whether the menu automatically enables and disables its menu items.

- update

Enables or disables the menu items of the menu based on the NSMenuValidation informal protocol and sizes the menu to fit its current menu items if necessary.

Getting and Setting the Menu Font

font

The font of the menu and its submenus.

Handling Keyboard Equivalents

- performKeyEquivalent:

Performs the action for the menu item that corresponds to the given key equivalent.

Simulating Mouse Clicks

- performActionForItemAtIndex:

Causes the application to send the action message of a specified menu item to its target.

Managing the Title

title

The title of the menu.

Configuring Menu Size

minimumWidth

The minimum width of the menu in screen coordinates.

size

The size of the menu in screen coordinates

- sizeToFit

Resizes the menu to exactly fit its items.

Deprecated

Getting Menu Properties

propertiesToUpdate

The available properties for the menu.

Managing Menu Change Notifications

menuChangedMessagesEnabled

Indicates whether messages are sent to the application’s windows each time the menu changes.

Deprecated

Displaying Contextual Menus

allowsContextMenuPlugIns

Indicates whether the pop-up menu allows appending of contextual menu plug-in items.

Displaying Context-Sensitive Help

+ popUpContextMenu:withEvent:forView:

Displays a contextual menu over a view for an event.

+ popUpContextMenu:withEvent:forView:withFont:

Displays a contextual menu over a view for an event using a specified font.

- helpRequested:

Overridden by subclasses to implement specialized context-sensitive help behavior.

Deprecated
- popUpMenuPositioningItem:atLocation:inView:

Pops up the menu at the specified location.

Managing Display of the State Column

showsStateColumn

Indicates whether the menu displays the state column.

Controlling Allocation Zones

+ menuZone

Returns the zone from which NSMenu objects should be allocated.

Deprecated
+ setMenuZone:

Sets the zone from which NSMenu objects should be allocated

Deprecated

Handling Highlighting

highlightedItem

Indicates the currently highlighted item in the menu.

Managing the User Interface

userInterfaceLayoutDirection

Configures the layout direction of menu items in the menu.

Managing the Delegate

delegate

The delegate of the menu.

Handling Tracking

- cancelTracking

Dismisses the menu and ends all menu tracking.

- cancelTrackingWithoutAnimation

Dismisses the menu and ends all menu tracking without displaying the associated animation.

Deprecated Methods

- contextMenuRepresentation

Deprecated.

Deprecated
- setContextMenuRepresentation:

Deprecated.

Deprecated
- tearOffMenuRepresentation

Deprecated.

Deprecated
- setTearOffMenuRepresentation:

Deprecated.

Deprecated
- setMenuRepresentation:

Deprecated.

Deprecated
- menuRepresentation

Deprecated.

Deprecated

Constants

NSMenuProperties

These constants are used as a bitmask for specifying a set of menu or menu item properties, and are contained by the propertiesToUpdate property.

Notifications

NSMenuDidAddItemNotification

Posted after a menu item is added to the menu.

NSMenuDidChangeItemNotification

Posted after a menu item in the menu changes appearance.

NSMenuDidBeginTrackingNotification

Posted when menu tracking begins.

NSMenuDidEndTrackingNotification

Posted when menu tracking ends, even if no action is sent.

NSMenuDidRemoveItemNotification

Posted after a menu item is removed from the menu.

NSMenuDidSendActionNotification

Posted just after the application dispatches a menu item’s action method to the menu item’s target.

NSMenuWillSendActionNotification

Posted just before the application dispatches a menu item’s action method to the menu item’s target.

Initializers

See Also

Menus

NSMenuItem

A command item in an app menu.

NSMenuDelegate

The optional methods implemented by delegates of NSMenu objects to manage menu display and handle some events.