The UILabel class implements a read-only text view. You can use this class to draw one or multiple lines of static text, such as those you might use to identify other parts of your user interface. The base UILabel class provides support for both simple and complex styling of the label text. You can also control over aspects of appearance, such as whether the label uses a shadow or draws with a highlight. If needed, you can customize the appearance of your text further by subclassing.


The default content mode of the UILabel class is redraw. This mode causes the view to redraw its contents every time its bounding rectangle changes. You can change this mode by modifying the inherited contentMode property of the class.

New label objects are configured to disregard user events and clip subviews by default. If you want to handle events in a custom subclass of UILabel, you must explicitly change the value of the isUserInteractionEnabled property to true after initializing the object. If you want to allow subviews to extend beyond the bounds of a label, you must explicitly change the value of the label’s clipsToBounds property to false.

For information about basic view behaviors, see View Programming Guide for iOS.

For more information about appearance and behavior configuration, see Labels in UIKit User Interface Catalog.


Accessing the Text Attributes

var text: String?

The text displayed by the label.

var attributedText: NSAttributedString?

The styled text displayed by the label.

var font: UIFont!

The font of the text.

var textColor: UIColor!

The color of the text.

var textAlignment: NSTextAlignment

The technique to use for aligning the text.

var lineBreakMode: NSLineBreakMode

The technique to use for wrapping and truncating the label’s text.

var isEnabled: Bool

The enabled state to use when drawing the label’s text.

Sizing the Label’s Text

var adjustsFontSizeToFitWidth: Bool

A Boolean value indicating whether the font size should be reduced in order to fit the title string into the label’s bounding rectangle.

var allowsDefaultTighteningForTruncation: Bool

A Boolean value indicating whether the label tightens text before truncating.

var baselineAdjustment: UIBaselineAdjustment

Controls how text baselines are adjusted when text needs to shrink to fit in the label.

var minimumScaleFactor: CGFloat

The minimum scale factor supported for the label’s text.

var numberOfLines: Int

The maximum number of lines to use for rendering text.

Managing Highlight Values

var highlightedTextColor: UIColor?

The highlight color applied to the label’s text.

var isHighlighted: Bool

A Boolean value indicating whether the receiver should be drawn with a highlight.

Drawing a Shadow

var shadowColor: UIColor?

The shadow color of the text.

var shadowOffset: CGSize

The shadow offset (measured in points) for the text.

Drawing and Positioning Overrides

func textRect(forBounds: CGRect, limitedToNumberOfLines: Int)

Returns the drawing rectangle for the label’s text.

func drawText(in: CGRect)

Draws the receiver’s text (or its shadow) in the specified rectangle.

Getting the Layout Constraints

var preferredMaxLayoutWidth: CGFloat

The preferred maximum width (in points) for a multiline label.

Setting and Getting Attributes

var isUserInteractionEnabled: Bool

A Boolean value that determines whether user events are ignored and removed from the event queue.