UIButton: currentTitle property
The currentTitle property is the title the button is displaying right now: the one selected by the current state.
Value
A string, or null.
- Read-only. Assigning to it throws
TypeError. - When the current state hasn't been set separately, it reads the one for the
normalstate. - There is no change notification. It changes with the button's state: when a finger touches down and lifts (the system fires control events such as
touchdownandtouchupinside), or when code changesisEnabledorisSelected. The state itself has no change event, so read it again at those moments. nullwhen no state has a title set.
Examples
js
const button = UIButton.buttonWithType('system');
button.setTitle('Submit', { forState: ['normal'] });
button.setTitle('Fill in the form first', { forState: ['disabled'] });
console.log(button.currentTitle);
button.isEnabled = false;
console.log(button.currentTitle);Result: First prints Submit; after disabling, prints Fill in the form first.
Corresponding iOS API
UIButton.currentTitle.
See also
- States: when the button is in which state