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
119
votes
11 answers

How to make URL/Phone-clickable UILabel?

I want to create a clickable label on my app leading me to a Safari webpage. I also want the user to be able to phone the numbers only by clicking on them ? Thanks for your advices
Rob
  • 14,827
  • 20
  • 65
  • 104
115
votes
20 answers

UILabel with text of two different colors

I want to display a string like this in a UILabel: There are 5 results. Where the number 5 is red in color and the rest of the string is black. How can I do this in code?
Peter
  • 1,151
  • 2
  • 8
  • 4
113
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
  • 35,175
  • 17
  • 147
  • 154
113
votes
4 answers

How does a UILabel's minimumScaleFactor work?

I have used minimumFontSize before but that function is now deprecated and i don't quite understand how minimumScaleFactor works. I want the maximum font size to be 10 and the minimum to be 7. How can I achieve the re-size down to font size 7 with…
Padin215
  • 7,266
  • 13
  • 58
  • 103
111
votes
20 answers

How to check if UILabel is truncated?

I have a UILabel that can be varying lengths depending on whether or not my app is running in portrait or landscape mode on an iPhone or iPad. When the text is too long to show on one line and it truncates I want the user to be able to press it and…
Randall
  • 14,070
  • 7
  • 36
  • 58
104
votes
11 answers

How to Increase Line spacing in UILabel in Swift

I have a label which has few lines of text and I want to increase the spacing between the lines. There are similar questions asked by others but the solutions don't solve my problems. Also my label may or may not contain paragraphs. I am new to…
Sneha
  • 1,959
  • 6
  • 20
  • 34
103
votes
22 answers

How to set top-left alignment for UILabel for iOS application?

I have added one label in my nib file, then its required to have top-left alignment for that lable. As I am providing text at runtime so its not sure that how much lines there are. So if text contains only single line then it appears as…
Mrunal
  • 13,474
  • 6
  • 48
  • 91
102
votes
10 answers

Set UILabel line spacing

How can I modify the gap between lines (line spacing) in a multiline UILabel?
Matrix
  • 7,431
  • 13
  • 61
  • 93
102
votes
4 answers

Handling Touch Event in UILabel and hooking it up to an IBAction

Ok, so I have a UILabel created in interface builder that displays some some default text of "tap to begin". When the user taps the UILabel I want it to trigger an IBAction method: -(IBAction)next; which updates the text on the label to say…
wfbarksdale
  • 6,962
  • 11
  • 60
  • 87
98
votes
2 answers

Setting UILabel text to bold

How do you set the text for a UILabel to bold in Swift programmatically? My code so far: var label = UILabel(frame:theFrame) label.text = "Foo"
bhzag
  • 2,694
  • 6
  • 20
  • 36
97
votes
18 answers

Use multiple font colors in a single label

Is there a way to use two, or even three font colors in a single label in iOS? If the text "hello, how are you" were used as an example, the "hello," would be blue, and the "how are you" would be green? Is this possible, it seems easier than…
Justin Rose
  • 1,015
  • 1
  • 10
  • 6
95
votes
12 answers

How to get UILabel to respond to tap?

I have discovered that I can create UILabel much faster than UITextField and I plan to use UILabel most of the time for my data display app. To make a long story short though, I wish to let the user tap on a UILabel and have my callback respond to…
Happy
  • 953
  • 1
  • 6
  • 4
92
votes
9 answers

Minimum Font Size deprecated on ios version 6.0

I just upgraded to xcode 4.5 with iOS 6.0 and it's highlighting a warning on all the UILabels in my XIB files saying "minimum font size deprecated on ios version 6.0". Does anyone know what this is referring to and how to fix it? Update: image is no…
Hooman Ahmadi
  • 1,397
  • 1
  • 12
  • 21
91
votes
10 answers

Format UILabel with bullet points?

Is it possible to format the text in a UILabel to show a bullet point? If so, How can I do it?
Rob
  • 6,575
  • 13
  • 56
  • 89
90
votes
21 answers

Underline text in UIlabel

How can I underline a text that could be multiple lines of string? I find some people suggest UIWebView, but it is obviously too heavy a class for just text rendering. My thoughts was to figure out the start point and length of each string in each…
semix
  • 919
  • 1
  • 7
  • 4