1.18. Customizing the UILabel
Problem
You want to be able to customize the appearance of your labels, from shadow settings to alignment settings.
Solution
Use the following properties of the UILabel class, depending on your
requirements:
shadowColorThis property is of type
UIColorand, as its name shows, it specifies the color of the drop shadow to render for your label. If you are setting this property, you should also set theshadowOffsetproperty.shadowOffsetThis property is of type
CGSize, and it specifies the offset of the drop shadow from the text. For instance, if you set this property to (1, 0), the drop shadow will appear 1 point to the right of the text. If you set this property to (1, 2), the drop shadow will appear 1 point to the right and 2 points down from the text. If you set this property to (–2, –10), the drop shadow will render 2 points to the left and 10 points above the text.numberOfLinesThis property is an integer that specifies how many lines of text the label is able to render. By default, this property’s value is set to 1, meaning any label that you create by default can handle 1 line of text. If you want 2 lines of text, for instance, set this property to 2. If you want unlimited lines of text to be rendered in your text field or you simply don’t know how many lines of text you will end up displaying, set this property to 0. (I know, it’s really strange. Instead of
NSIntegerMaxor something similar, Apple has decided that 0 means unlimited!)lineBreakModeThis ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access