An object that manages an app’s menus.
SDK
- macOS 10.0+
Framework
- App
Kit
Declaration
class NSMenu : NSObject
An object that manages an app’s menus.
SDK
Framework
class NSMenu : NSObject
class func menu Bar Visible() -> Bool
Returns a Boolean value that indicates whether the menu bar is visible.
class func set Menu Bar Visible(Bool)
Sets whether the menu bar is visible and selectable by the user.
var menu Bar Height: CGFloat
The menu bar height for the main menu in pixels.
init(title: String)
Initializes and returns a menu having the specified title and with autoenabling of menu items turned on.
func insert Item(NSMenu Item, at: Int)
Inserts a menu item into the menu at a specific location.
func insert Item(with Title: String, action: Selector?, key Equivalent: String, at: Int) -> NSMenu Item
Creates and adds a menu item at a specified location in the menu.
func add Item(NSMenu Item)
Adds a menu item to the end of the menu.
func add Item(with Title: String, action: Selector?, key Equivalent: String) -> NSMenu Item
Creates a new menu item and adds it to the end of the menu.
func remove Item(NSMenu Item)
Removes a menu item from the menu.
func remove Item(at: Int)
Removes the menu item at a specified location in the menu.
func item Changed(NSMenu Item)
Invoked when a menu item is modified visually (for example, its title changes).
func remove All Items()
Removes all the menu items in the menu.
func item(with Tag: Int) -> NSMenu Item?
Returns the first menu item in the menu with the specified tag.
func item(with Title: String) -> NSMenu Item?
Returns the first menu item in the menu with a specified title.
func item(at: Int) -> NSMenu Item?
Returns the menu item at a specific location of the menu.
var number Of Items: Int
The number of menu items in the menu, including separator items.
var items: [NSMenu Item]
An array containing the menu items in the menu.
func index(of: NSMenu Item) -> Int
Returns the index identifying the location of a specified menu item in the menu.
func index Of Item(with Title: String) -> Int
Returns the index of the first menu item in the menu that has a specified title.
func index Of Item(with Tag: Int) -> Int
Returns the index of the first menu item in the menu identified by a tag.
func index Of Item(with Target: Any?, and Action: Selector?) -> Int
Returns the index of the first menu item in the menu that has a specified action and target.
func index Of Item(with Represented Object: Any?) -> Int
Returns the index of the first menu item in the menu that has a given represented object.
func index Of Item(with Submenu: NSMenu?) -> Int
Returns the index of the menu item in the menu with the given submenu.
func set Submenu(NSMenu?, for: NSMenu Item)
Assigns a menu to be a submenu of the menu controlled by a given menu item.
func submenu Action(Any?)
The action method assigned to menu items that open submenus.
var supermenu: NSMenu?
The parent menu that contains the menu as a submenu.
var is Torn Off: Bool
Indicates whether the menu is offscreen or attached to another menu (or if it’s the main menu).
var autoenables Items: Bool
Indicates whether the menu automatically enables and disables its menu items.
func 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.
var font: NSFont!
The font of the menu and its submenus.
func perform Key Equivalent(with: NSEvent) -> Bool
Performs the action for the menu item that corresponds to the given key equivalent.
func perform Action For Item(at: Int)
Causes the application to send the action message of a specified menu item to its target.
var title: String
The title of the menu.
var minimum Width: CGFloat
The minimum width of the menu in screen coordinates.
var size: NSSize
The size of the menu in screen coordinates
var properties To Update: NSMenu .Properties
The available properties for the menu.
var menu Changed Messages Enabled: Bool
Indicates whether messages are sent to the application’s windows each time the menu changes.
var allows Context Menu Plug Ins: Bool
Indicates whether the pop-up menu allows appending of contextual menu plug-in items.
class func pop Up Context Menu(NSMenu, with: NSEvent, for: NSView)
Displays a contextual menu over a view for an event.
class func pop Up Context Menu(NSMenu, with: NSEvent, for: NSView, with: NSFont?)
Displays a contextual menu over a view for an event using a specified font.
func help Requested(with: NSEvent)
Overridden by subclasses to implement specialized context-sensitive help behavior.
func pop Up(positioning: NSMenu Item?, at: NSPoint, in: NSView?) -> Bool
Pops up the menu at the specified location.
var shows State Column: Bool
Indicates whether the menu displays the state column.
class func menu Zone() -> NSZone!
Returns the zone from which NSMenu
objects should be allocated.
var highlighted Item: NSMenu Item?
Indicates the currently highlighted item in the menu.
var user Interface Layout Direction: NSUser Interface Layout Direction
Configures the layout direction of menu items in the menu.
var delegate: NSMenu Delegate?
The delegate of the menu.
func cancel Tracking()
Dismisses the menu and ends all menu tracking.
func cancel Tracking Without Animation()
Dismisses the menu and ends all menu tracking without displaying the associated animation.
struct NSMenu .Properties
These constants are used as a bitmask for specifying a set of menu or menu item properties, and are contained by the properties
property.
class let did Add Item Notification: NSNotification .Name
Posted after a menu item is added to the menu.
class let did Change Item Notification: NSNotification .Name
Posted after a menu item in the menu changes appearance.
class let did Begin Tracking Notification: NSNotification .Name
Posted when menu tracking begins.
class let did End Tracking Notification: NSNotification .Name
Posted when menu tracking ends, even if no action is sent.
class let did Remove Item Notification: NSNotification .Name
Posted after a menu item is removed from the menu.
class let did Send Action Notification: NSNotification .Name
Posted just after the application dispatches a menu item’s action method to the menu item’s target.
class let will Send Action Notification: NSNotification .Name
Posted just before the application dispatches a menu item’s action method to the menu item’s target.
class NSMenu Item
A command item in an app menu.
protocol NSMenu Delegate
The optional methods implemented by delegates of NSMenu
objects to manage menu display and handle some events.