Class

NSPop​Up​Button

The NSPop​Up​Button class defines objects that implement the pop-up and pull-down menus of the graphical user interface.

Overview

An NSPop​Up​Button object uses an NSPop​Up​Button​Cell object to implement its user interface.

Note that while a menu is tracking user input, programmatic changes to the menu such as adding, removing, or changing items on the menu is not reflected.

Symbols

Initializing an NSPopUpButton

init(frame:​ NSRect, pulls​Down:​ Bool)

Returns an NSPop​Up​Button object initialized to the specified dimensions.

Setting the type of menu

var pulls​Down:​ Bool

A Boolean value indicating whether the button displays a pull-down or pop-up menu.

var autoenables​Items:​ Bool

A Boolean value indicating whether the button enables and disables its items every time a user event occurs.

Inserting and deleting items

func add​Item(with​Title:​ String)

Adds an item with the specified title to the end of the menu.

func add​Items(with​Titles:​ [String])

Adds multiple items to the end of the menu.

func insert​Item(with​Title:​ String, at:​ Int)

Inserts an item at the specified position in the menu.

func remove​All​Items()

Removes all items in the receiver’s item menu.

func remove​Item(with​Title:​ String)

Removes the item with the specified title from the menu.

func remove​Item(at:​ Int)

Removes the item at the specified index.

Getting the user’s selection

var selected​Item:​ NSMenu​Item?

The menu item that was last selected by the user.

var title​Of​Selected​Item:​ String?

The title of the item that was last selected by the user.

var index​Of​Selected​Item:​ Int

The index of the item that was last selected by the user.

Setting the current selection

func select(NSMenu​Item?)

Selects the specified menu item.

func select​Item(at:​ Int)

Selects the item in the menu at the specified index.

func select​Item(with​Tag:​ Int)

Selects the menu item with the specified tag.

func select​Item(with​Title:​ String)

Selects the item with the specified title.

Getting menu items

var menu:​ NSMenu?

The menu associated with the pop-up button.

var number​Of​Items:​ Int

The number of items in the menu.

var item​Array:​ [NSMenu​Item]

The array of menu item objects associated with the button.

func item(at:​ Int)

Returns the menu item at the specified index.

func item​Title(at:​ Int)

Returns the title of the item at the specified index.

var item​Titles:​ [String]

An array of strings corresponding to the titles of the items in the menu.

func item(with​Title:​ String)

Returns the menu item with the specified title.

var last​Item:​ NSMenu​Item?

The last item in the menu.

Getting the indices of menu items

func index(of:​ NSMenu​Item)

Returns the index of the specified menu item.

func index​Of​Item(with​Tag:​ Int)

Returns the index of the menu item with the specified tag.

func index​Of​Item(with​Title:​ String)

Returns the index of the item with the specified title.

func index​Of​Item(with​Represented​Object:​ Any?)

Returns the index of the menu item that holds the specified represented object.

func index​Of​Item(with​Target:​ Any?, and​Action:​ Selector?)

Returns the index of the menu item with the specified target and action.

Setting the cell edge to pop out in restricted situations

var preferred​Edge:​ NSRect​Edge

The edge of the button on which to display the menu when screen space is constrained.

Setting the title

func set​Title(String)

Sets the string displayed in the receiver when the user isn’t pressing the mouse button.

Setting the state

func synchronize​Title​And​Selected​Item()

Ensures that the item being displayed by the receiver agrees with the selected item.

Notifications

static let NSPop​Up​Button​Will​Pop​Up:​ NSNotification.Name

Posted when an NSPop​Up​Button object receives a mouse-down event—that is, when the user is about to select an item from the menu.

Instance Methods