<!--
{
  "availability" : [
    "macOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSButton/state",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Property",
  "symbol" : {
    "kind" : "Instance Property",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(cs)NSButton(py)state"
  },
  "title" : "state"
}
-->

# state

The button’s state.

```
var state: NSControl.StateValue { get set }
```

## Discussion

The value of this property represents the button’s state. A button can have two or three states.  If it has two, this value is either on (`NSOnState`) or off (`NSOffState`). If it has three, this value is on, off, or mixed (`NSMixedState`). A three-state button can be enabled by calling the [`allowsMixedState`](/documentation/AppKit/NSButton/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 is used to denote whether a text field contains bold text. If all of the text in the text field is bold, then the checkbox appears checked (on). If none of the text is bold, then the checkbox appears unchecked (off). If some of the text is bold, then the checkbox contains a dash (mixed).

Note that if the button has only two states and you set the value of [`state`](/documentation/AppKit/NSButton/state) to mixed, the button’s state changes to on. Setting this property redraws the button, if necessary.

Although using the enumerated constants is preferred, you can also set [`state`](/documentation/AppKit/NSButton/state) to an integer value. If the button has two states, `0` is treated as `NSOffState`, and a nonzero value is treated as `NSOnState`. If the button has three states, `0` is treated as `NSOffState`; a negative value, as `NSMixedState`; and a positive value, as `NSOnState`.

To check whether the button uses the mixed state, use the [`allowsMixedState`](/documentation/AppKit/NSButton/allowsMixedState) property.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)