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
74
votes
6 answers

How can you rotate text for UIButton and UILabel in Swift?

How can you rotate text for UIButton and UILabel? 90 degrees, 180 degrees. Note: Before you mark this as a duplicate, I am intentionally modelling my question as a Swift version of this one: How can you rotate text for UIButton and UILabel in…
Suragch
  • 484,302
  • 314
  • 1,365
  • 1,393
73
votes
11 answers

How to achieve UIButton / UILabel 'padding' in iPhone app

I've got various views in my iPhone application that require padding e.g a custom UIButton with text aligned left, and a UILabel with a background color. This may be a really stupid question, but how can I apply 'padding' to move the text off the…
user210437
71
votes
6 answers

UILabel - string as text and links

I have a UILabel whose text I am getting from a server. Some of the text is to be identified as links, and on touching those links some action should be performed. e.g. NSString *str = @"My phone number is 645-345-2345 and my address is xyz"; This…
Nitish
  • 13,845
  • 28
  • 135
  • 263
70
votes
7 answers

How can you rotate text for UIButton and UILabel in Objective-C?

How can you rotate text for UIButton and UILabel? 90 degrees, 180 degrees.
jdl
  • 6,151
  • 19
  • 83
  • 132
70
votes
14 answers

Change character spacing on UILabel within Interface Builder

Is there anyway to change the character spacing (track) on UILabel text using Interface Builder? If not, is there a way to do it programmatically on an existing UILabel that was already created with attributed text?
codeman
  • 8,868
  • 13
  • 50
  • 79
70
votes
7 answers

Is it possible to get a listing of attributes and ranges for an NSMutableAttributedString?

I've created a method that takes a NSAttributedString and I'm looking to dynamically create a subview and label to put the string into. Because attributes like font and size need to be determined to correctly determine the size of the label, I need…
propstm
  • 3,461
  • 5
  • 28
  • 41
70
votes
13 answers

Add left/right horizontal padding to UILabel

I need to create a UILabel with a background color, and I'd like to add some left/right leading/trailing horizontal padding. But every solution I've found seems like a nasty hack. What is the 'standard' way to achieve this from iOS 5 forward? A…
ssantos
  • 16,001
  • 7
  • 50
  • 70
69
votes
6 answers

Adding underline to UILabel attributed string from the storyboard fails

From the storyboard I select the UILabel in question Then in Attribute Inspector > Label > [I choose] Attributed Also in Attribute Inspector > Label > Text> [I select the content] Then I click on the font icon and choose underline Basically, any…
Katedral Pillon
  • 14,534
  • 25
  • 99
  • 199
68
votes
17 answers

Vertically align text within a UILabel (Note : Using AutoLayout)

I am Copying the same Question asked Before Question. I have tried the solutions given and was not able to solve it since sizetofit was not effective when I use Autolayout. The expected display is like below.
MELWIN
  • 1,093
  • 4
  • 12
  • 19
68
votes
10 answers

iPhone - UILabel containing text with multiple fonts at the same time

I am looking for a way to use a UILabel (or something similar) to display something like this: Tom: Some message. It is like how it's done in for example the Facebook app to display the "what's on your mind?" messages. Does anyone have any…
Tom van Zummeren
  • 9,130
  • 12
  • 52
  • 63
67
votes
8 answers

UILabel wrong word wrap in iOS 11

I have problem with application using XIBs without autolayout. I don't know if this is important information. I have UILabel with 2 lines using word wrap. In iOS 10 word wrap was working correctly, and first line contained one word + special…
studentbi
  • 805
  • 1
  • 6
  • 6
66
votes
6 answers

make UILabel's text bold

I want to make UILabel's text bold infoLabel=[[UILabel alloc]initWithFrame:CGRectMake(90,150, 200, 30)]; [infoLabel setText:@"Drag 14 more Flavors"]; [infoLabel setBackgroundColor:[UIColor clearColor]]; [infoLabel setFont:[UIFont…
Ali
  • 10,774
  • 10
  • 56
  • 83
66
votes
6 answers

Can not change UILabel text color

I want to change the UILabel text color but I can't change the color, This is how my code looks like. UILabel *categoryTitle = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 46, 16)]; categoryTitle.text = @"abc"; categoryTitle.backgroundColor =…
HelloWorld
  • 7,156
  • 6
  • 39
  • 36
65
votes
2 answers

Text not vertically centered in UILabel

I've created a Label with the following code : func setupValueLabel() { valueLabel.numberOfLines = 1 valueLabel.font = UIFont(name: "Avenir-Black", size: 50) valueLabel.adjustsFontSizeToFitWidth = true valueLabel.clipsToBounds =…
Loadex
  • 1,502
  • 1
  • 12
  • 25
63
votes
17 answers

Autoshrink on a UILabel with multiple lines

Is it possible to use the autoshrink property in conjunction on multiple lines on a UILabel? for example, the large text size possible on 2 available lines.
jfisk
  • 6,125
  • 20
  • 77
  • 113