Questions tagged [uilabel]

The UILabel class implements a read-only text view in iOS. 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.

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 UIViewContentModeRedraw. 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 userInteractionEnabled property to YES 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 NO.

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.

7081 questions
198
votes
8 answers

UIlabel layer.cornerRadius not working in iOS 7.1

I'm currently looking at a UILabel with the property addMessageLabel.layer.cornerRadius = 5.0f; On a device with iOS 7.0 installed, it has rounded corners. On a device with iOS 7.1 installed, it does not have rounded corners. Is this just a bug with…
mverderese
  • 5,314
  • 6
  • 27
  • 36
191
votes
8 answers

iOS: Multi-line UILabel in Auto Layout

I'm having trouble trying to achieve some very basic layout behavior with Auto Layout. My view controller looks like this in IB: The top label is the title label, I don't know how many lines it will be. I need the title label to display all lines…
James Harpe
  • 4,315
  • 8
  • 47
  • 74
171
votes
12 answers

How to make a UILabel clickable?

I would like to make a UILabel clickable. I have tried this, but it doesn't work: class DetailViewController: UIViewController { @IBOutlet weak var tripDetails: UILabel! override func viewDidLoad() { super.viewDidLoad() …
Daniele B
  • 19,801
  • 29
  • 115
  • 173
160
votes
5 answers

UILabel - Wordwrap text

Is there any way to have a label wordwrap text as needed? I have the line breaks set to word wrap and the label is tall enough for two lines, but it appears that it will only wrap on line breaks. Do I have to add line breaks to make it wrap…
Codezy
  • 5,540
  • 7
  • 39
  • 48
159
votes
13 answers

UILabel sizeToFit doesn't work with autolayout ios6

How am I supposed to configure programmatically (and in which method) a UILabel whose height depends on its text? I've been trying to set it up using a combination of Storyboard and code, but to no avail. Everyone recommends sizeToFit while…
circuitlego
  • 3,469
  • 5
  • 22
  • 22
155
votes
15 answers

UILabel - auto-size label to fit text?

Is it possible to auto-resize the UILabel box/bounds to fit the contained text? (I don't care if it ends up larger than the display) So if a user enters "hello" or "my name is really long i want it to fit in this box", it is never truncated and the…
wayneh
  • 4,393
  • 9
  • 35
  • 70
155
votes
14 answers

Animate text change in UILabel

I'm setting a new text value to a UILabel. Currently, the new text appears just fine. However, I'd like to add some animation when the new text appears. I'm wondering what I can do to animate the appearance of the new text.
Joo Park
  • 3,115
  • 4
  • 27
  • 31
154
votes
16 answers

How do I create a round cornered UILabel on the iPhone?

Is there a built in way to create round-cornered UILabels? If the answer is no, how would one go about creating such an object?
newtonapple
  • 4,123
  • 3
  • 33
  • 31
154
votes
9 answers

How to draw border around a UILabel?

Is there a way for UILabel to draw a border around itself? This is useful for me to debug the text placement and to see the placement and how big the label actually is.
Boon
  • 40,656
  • 60
  • 209
  • 315
153
votes
19 answers

How do I set bold and italic on UILabel of iPhone/iPad?

How do I set bold and italic on UILabel of iPhone/iPad? I searched the forum but nothing helped me. Could anyone help me?
Edi
  • 1,728
  • 2
  • 13
  • 13
147
votes
8 answers

How to calculate UILabel width based on text length?

I want to display an image next to a UILabel, however UILabel has variable text length, so I don't know where to place the image. How can I accomplish this?
Sheehan Alam
  • 60,111
  • 124
  • 355
  • 556
145
votes
21 answers

How can I create a UILabel with strikethrough text?

I want to create a UILabel in which the text is like this How can I do this? When the text is small, the line should also be small.
Dev
  • 3,885
  • 10
  • 39
  • 65
143
votes
11 answers

iOS multiline label in Interface builder

How can I make a multiline UILabel in interface builder for iOS? I tried the UITextView but it didn't quite suit my needs. How can I add multiline (text) in label?
Samuli Lehtonen
  • 3,840
  • 5
  • 39
  • 49
143
votes
11 answers

Center NSTextAttachment image next to single line UILabel

I'd like to append an NSTextAttachment image to my attributed string and have it centered vertically. I've used the following code to create my string: NSMutableAttributedString *str = [[NSMutableAttributedString alloc]…
Sean Danzeiser
  • 9,141
  • 12
  • 52
  • 90
140
votes
16 answers

How to underline a UILabel in swift?

How to underline a UILabel in Swift? I searched the Objective-C ones but couldn't quite get them to work in Swift.
Esqarrouth
  • 38,543
  • 21
  • 161
  • 168