A control that defines an area on the screen that can be used to trigger actions.
- macOS 10.0+
Buttons are a standard control used to initiate actions within your app. You can configure buttons with many different visual styles, but the behavior is the same. When clicked, a button calls the action method of its associated target object. (If you configure a button as continuous, it calls its action method at timed intervals until the user releases the mouse button or the cursor leaves the button boundaries.) You use the action method to perform your app-specific tasks.
If you configure it as an accelerator button (type
NSMulti), 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
allows 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
NSButton 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.