Class

NSPopUpButton

The NSPopUpButton class defines objects that implement the pop-up and pull-down menus of the graphical user interface.

Overview

An NSPopUpButton object uses an NSPopUpButtonCell 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, pullsDown: Bool)

Returns an NSPopUpButton object initialized to the specified dimensions.

Setting the type of menu

var pullsDown: Bool

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

var autoenablesItems: Bool

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

Inserting and deleting items

func addItem(withTitle: String)

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

func addItems(withTitles: [String])

Adds multiple items to the end of the menu.

func insertItem(withTitle: String, at: Int)

Inserts an item at the specified position in the menu.

func removeAllItems()

Removes all items in the receiver’s item menu.

func removeItem(withTitle: String)

Removes the item with the specified title from the menu.

func removeItem(at: Int)

Removes the item at the specified index.

Getting the user’s selection

var selectedItem: NSMenuItem?

The menu item that was last selected by the user.

var titleOfSelectedItem: String?

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

var indexOfSelectedItem: Int

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

Setting the current selection

func select(NSMenuItem?)

Selects the specified menu item.

func selectItem(at: Int)

Selects the item in the menu at the specified index.

func selectItem(withTag: Int)

Selects the menu item with the specified tag.

func selectItem(withTitle: String)

Selects the item with the specified title.

Getting menu items

var menu: NSMenu?

The menu associated with the pop-up button.

var numberOfItems: Int

The number of items in the menu.

var itemArray: [NSMenuItem]

The array of menu item objects associated with the button.

func item(at: Int)

Returns the menu item at the specified index.

func itemTitle(at: Int)

Returns the title of the item at the specified index.

var itemTitles: [String]

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

func item(withTitle: String)

Returns the menu item with the specified title.

var lastItem: NSMenuItem?

The last item in the menu.

Getting the indices of menu items

func index(of: NSMenuItem)

Returns the index of the specified menu item.

func indexOfItem(withTag: Int)

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

func indexOfItem(withTitle: String)

Returns the index of the item with the specified title.

func indexOfItem(withRepresentedObject: Any?)

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

func indexOfItem(withTarget: Any?, andAction: 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 preferredEdge: NSRectEdge

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

Setting the title

func setTitle(String)

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

Setting the state

func synchronizeTitleAndSelectedItem()

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

Notifications

static let NSPopUpButtonWillPopUp: NSNotification.Name

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

Instance Methods

Relationships

Inherits From