Skip to content

UIControl: state property ​

The state property is all of the control's current states, combined from isEnabled, isSelected, and isHighlighted.

Value ​

An array of state names. The state names are the following strings:

State nameWhen it is in the array
'normal'None of the four below holds. The array then contains only this item
'highlighted'isHighlighted is true
'disabled'isEnabled is false
'selected'isSelected is true
'focused'The control has focus. When it gains focus is not verified in the simulator
  • Read-only; assigning to it throws TypeError.
  • Defaults to ['normal'].
  • When several states hold at once, the array has several items. Their order is not guaranteed; check for a state with includes(), not by index.

Observing changes ​

No event fires when it changes; for why, see States. To change the state, write isEnabled, isSelected, or isHighlighted.

Examples ​

js
const card = new UIControl();
console.log(card.state.join(', '));

card.isSelected = true;
card.isEnabled = false;
console.log(card.state.includes('disabled'), card.state.includes('selected'));

Result: prints normal first, then true true.

Corresponding iOS API ​

UIControl.state. Natively it is a bitmask; state & UIControlStateSelected is written state.includes('selected').

See also ​