UIButton: titleLabel property
The titleLabel property is the UILabel inside the button that displays the title. The button itself has no properties such as font or number of lines; set them through this label.
Value
UILabel, or null.
- Read-only. Assigning to it throws
TypeError. - A
systembutton'stitleLabelhas a value, and itstextis the title currently displayed. Other button types are not verified in the simulator. - Its type allows
null, so check before using it.
Note: Don't change the title text or color through
titleLabel; usesetTitle()andsetTitleColor(). If you changetitleLabel.textdirectly, the button switches it back the next time its state changes.
Examples
js
const button = UIButton.buttonWithType('system');
button.setTitle('Submit', { forState: ['normal'] });
const label = button.titleLabel;
if (label) {
label.font = UIFont.systemFontOfSize(20, { weight: 'semibold' });
}Effect: The title becomes 20 pt semibold.
Corresponding iOS API
UIButton.titleLabel.