UIButton: currentAttributedTitle property
The currentAttributedTitle property is the styled title the button is displaying right now: the one selected by the current state.
Value
NSAttributedString, 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 been set withsetAttributedTitle().
Examples
js
const button = UIButton.buttonWithType('system');
console.log(button.currentAttributedTitle);
button.setAttributedTitle(new NSAttributedString('Submit', { foregroundColor: 'systemBlue' }),
{ forState: ['normal'] });
console.log(button.currentAttributedTitle !== null);Result: First prints null, then true.
Corresponding iOS API
UIButton.currentAttributedTitle.
See also
- States: when the button is in which state