Cover by Vandad Nahavandipoor

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

O'Reilly logo

2.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:

shadowColor

This property is of type UIColor and, as its name shows, it specifies the color of the dropshadow to render for your label. If you are setting this property, you should also set the shadowOffset property.

shadowOffset

This property is of type CGSize and it specifies the offset of the dropshadow from the text. For instance, if you set this property to (1, 0), the dropshadow will appear 1 point to the right of the text. If you set this property to (1, 2), the dropshadow will appear 1 point to the right and 2 points down from the text. If you set this property to (-2, -10), the dropshadow will render 2 points to the left and 10 points above the text.

numberOfLines

This 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 NSIntegerMax or something similar, Apple has decided that 0 means unlimited!)

lineBreakMode

This property ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required