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.

6945 questions
190
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,274
  • 7
  • 42
  • 74
173
votes
21 answers

Multiline label in UIStackView

When putting multiline label (with linebreak set to Word Wrap) into a stack view, the label immediately loses the linebreak and displays the label text in one line instead. Why is this happening and how does one preserve multiline label within a…
Boon
  • 37,606
  • 51
  • 186
  • 296
155
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,349
  • 5
  • 19
  • 22
153
votes
4 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,340
  • 7
  • 35
  • 47
152
votes
11 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
  • 16,703
  • 21
  • 96
  • 154
150
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,053
  • 2
  • 30
  • 29
147
votes
14 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,093
  • 8
  • 29
  • 64
147
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
  • 37,606
  • 51
  • 186
  • 296
145
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,648
  • 2
  • 13
  • 13
145
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
  • 57,155
  • 123
  • 348
  • 546
141
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
  • 2,955
  • 4
  • 24
  • 31
139
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,780
  • 4
  • 36
  • 45
134
votes
20 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,655
  • 10
  • 36
  • 62
126
votes
10 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
  • 8,731
  • 12
  • 49
  • 84
119
votes
17 answers

Adjust UILabel height to text

I have some labels which I want to adjust their height to the text, this is the code I wrote for this now func heightForView(text:String, font:UIFont, width:CGFloat) -> CGFloat{ let label:UILabel = UILabel(frame: CGRectMake(0, 0, width,…
TheBurgerShot
  • 1,446
  • 2
  • 11
  • 20