Class

NSButton​Cell

The NSButton​Cell class is a subclass of NSAction​Cell. An NSButton​Cell object defines the user interface of a button, checkbox (switch), radio button, and any other clickable region of a view. For example, the NSButton subclass of NSControl uses a single NSButton​Cell object to implement its user interface. The configuration of the NSButton​Cell object controls how the NSButton object appears and behaves, but the NSButton object is what sends a message when clicked.

Overview

Setting the integer, float, double, or object value of an NSButton​Cell object results in a call to state with the value converted to integer. In the case of object​Value, nil is equivalent to 0, and a non-nil object that doesn't respond to int​Value sets the state to 1. Otherwise, the state is set to the object's int​Value. Similarly, for most button types, querying the integer, float, double, or object value of an NSButton​Cell returns the current state in the requested representation. In the case of object​Value, this is an NSNumber containing true for on, false for off, and integer value -1 for the mixed state. For accelerator buttons (type NSAccelerator​Button or NSMulti​Level​Accelerator​Button) on systems that support pressure sensitivity, querying double​Value returns the amount of pressure applied while pressing the button.

For more information on the behavior of NSButton​Cell, see the NSButton and NSMatrix class specifications, and Button Programming Topics.

Exceptions

In its implementation of the compare(_:​) method (declared in NSCell), NSButton​Cell raises an NSBad​Comparison​Exception if the other​Cell argument is not of the NSButton​Cell class.

Symbols

Setting Titles

var alternate​Title:​ String

The string displayed by the button when it’s in its alternate state.

var attributed​Alternate​Title:​ NSAttributed​String

The title displayed by the button when it’s in its alternate state, as an attributed string.

var attributed​Title:​ NSAttributed​String

The title displayed by the button when it’s in its normal state as an attributed string.

var title:​ String!

The title displayed on the button when it’s in its normal state.

Managing Images

var alternate​Image:​ NSImage?

The image the button displays in its alternate state.

var image​Position:​ NSCell​Image​Position

The position of the button’s image relative to its title.

var image​Scaling:​ NSImage​Scaling

The scale factor for the button’s image.

Managing the Repeat Interval

func get​Periodic​Delay(Unsafe​Mutable​Pointer<Float>, interval:​ Unsafe​Mutable​Pointer<Float>)

Returns by reference the delay and interval periods for a continuous button.

func set​Periodic​Delay(Float, interval:​ Float)

Sets the message delay and interval for the button.

Managing the Key Equivalent

var key​Equivalent:​ String

The button’s key-equivalent character.

var key​Equivalent​Font:​ NSFont?

The font used to draw the button’s key equivalent.

var key​Equivalent​Modifier​Mask:​ NSEvent​Modifier​Flags

The mask that identifies the modifier keys for the button's key equivalent.

func set​Key​Equivalent​Font(String, size:​ CGFloat)

Sets by name and size of the font used to draw the key equivalent.

Managing Graphics Attributes

var background​Color:​ NSColor?

The background color of the button.

var bezel​Style:​ NSBezel​Style

The appearance of the button’s border, if it has one.

var gradient​Type:​ NSGradient​Type

The gradient of the button’s border.

Deprecated
var image​Dims​When​Disabled:​ Bool

A Boolean value that indicates if the button’s image and text appear “dim” when the button is disabled.

var is​Opaque:​ Bool

A Boolean value that indicates if the button is opaque.

var is​Transparent:​ Bool

A Boolean value that indicates if the button is transparent.

var shows​Border​Only​While​Mouse​Inside:​ Bool

A Boolean value that indicates if the button displays its border only when the pointer is over it.

Displaying the Cell

var highlights​By:​ NSCell​Style​Mask

A set of flags that indicate how the button highlights when it receives a mouse-down event (that is, when the button is pressed).

func set​Button​Type(NSButton​Type)

Sets how the button highlights while pressed and how it shows its state.

var shows​State​By:​ NSCell​Style​Mask

The flags that indicate how the button cell shows its alternate state.

Managing the Sound

var sound:​ NSSound?

The sound that’s played when the user presses the button (that is during a mouse-down event).

Handling Events and Action Messages

func mouse​Entered(with:​ NSEvent)

Draws the button’s border.

func mouse​Exited(with:​ NSEvent)

Erases the button’s border.

func perform​Click(Any?)

Simulates the user clicking the button with the pointer.

Drawing the Button Content

func draw​Bezel(with​Frame:​ NSRect, in:​ NSView)

Draws the border of the button using the current bezel style.

func draw​Image(NSImage, with​Frame:​ NSRect, in:​ NSView)

Draws the image associated with the button’s current state.

func draw​Title(NSAttributed​String, with​Frame:​ NSRect, in:​ NSView)

Draws the button’s title centered vertically in a specified rectangle.

Constants

NSBezel​Style

Bezel styles used by the bezel​Style property.

NSButton​Type

Button types that can be specified using set​Button​Type(_:​).

NSGradient​Type

Specify the gradients used by the gradient​Type property.

Deprecated

Relationships

Inherits From