UIControl: isHighlighted property
The isHighlighted property indicates whether the control is in the highlighted state, that is, whether a finger is pressed on the control.
Value
A boolean.
| Value | Effect |
|---|---|
true | The control enters the highlighted state. state contains 'highlighted'. A button switches to its pressed appearance |
false | The control leaves the highlighted state |
- Readable and writable.
- Defaults to
false. - The system sets it to
trueautomatically when a finger presses down, and back tofalsewhen the finger is lifted or the touch is canceled. The app's code can also write it. - Writes are converted by JS truthiness.
Observing changes
No event fires when it changes. Use touchdown and the three ending events touchupinside, touchupoutside, and touchcancel to learn when a touch starts and ends.
Note: Do not read it in an event callback to decide whether a finger is held down. Callbacks run after the touch; when a finger is lifted quickly after pressing, reading it in the
touchdowncallback may already givefalse(measured); see When callbacks run. To change the appearance on press, change it directly in thetouchdowncallback.
Examples
js
const card = new UIControl();
card.isHighlighted = true;
console.log(card.state.includes('highlighted'));Result: prints true.
Corresponding iOS API
UIControl.highlighted; its getter is isHighlighted.
See also
isTracking: whether the control is tracking a touch- States