UILabel: font property
The font property is the font of the label's text, including size and weight.
Value
A UIFont.
- Readable and writable.
- The default is the system font at 17 pt.
- Writing
nullrestores the default. It never reads asnull. - The object read is the one written:
label.font === the object writtenistrue. - A
UIFontcannot be modified. To change the size or weight, create a newUIFontand assign it. - The label's font size does not automatically follow the text size the user sets in system settings; to follow it, reassign when the setting changes. See the guide Setting fonts.
- When
adjustsFontSizeToFitWidthhas shrunk the font size,fontstill reads as the original font and does not reflect the shrunken size. Not verified in the simulator.
Invalid values
TypeError
The value written is neither a UIFont object nor null, such as label.font = 'Helvetica'.
Examples
js
const label = new UILabel();
label.text = 'Title';
label.font = UIFont.systemFontOfSize(20, { weight: 'semibold' });Effect: The text becomes the 20 pt semibold system font.
js
const label = new UILabel();
label.text = '12:30';
label.font = UIFont.monospacedSystemFontOfSize(20, { weight: 'medium' });Effect: Every character takes the same width, which suits numbers and code.
Corresponding iOS API
UILabel.font.
See also
UIFont: every way to create a font