NSButton is a subclass of the
NSControl class. An
NSButton object sends an action message to a target object, such as a view controller, when the button is clicked. When configured as continuous, the button continues to send repeating action messages at timed intervals until released.
- macOS 10.10+
If you configure it as an accelerator button (type
NSMultiLevelAcceleratorButton), a button can be set to send action messages when changes in pressure occur when the user clicks on the button.
Buttons can either have two states (on and off) or three states (on, off, and mixed). You enable a three-state button by calling the
allowsMixedState method. On and off states (also referred to as alternate and normal) indicate that the button is either clicked or not clicked. Mixed state is typically used for checkboxes or radio buttons, which allow for an additional intermediate state. For example, suppose the state of a checkbox denotes whether a text field contains bold text. If all of the text in the text field is bold, then the checkbox is on. If none of the text is bold, then the checkbox is off. If some of the text is bold, then the checkbox is mixed.
For most types of buttons, the value of the button matches its state—the value is
1 for on,
0 for off, or
-1 for mixed. For pressure-sensitive buttons, the value of the button indicates pressure level instead.
NSMatrix both provide a control view, which displays an
NSButtonCell object. However, while a matrix requires you to access the button cell objects directly, most button class methods act as “covers” for identically declared button cell methods. In other words, the implementation of the button method invokes the corresponding button cell method for you, allowing you to be unconcerned with the existence of the button cell. The only button cell methods that don’t have covers relate to the font used to display the key equivalent and to specific methods for highlighting or showing the state of the button.