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
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
17 answers

How to find actual number of lines of UILabel?

How can I find the actual number of lines of a UILabel after I have initialized it with a text and a font? I have set its numberOfLines property to 0, so it will expand to however many lines are necessary. But then, how can I find out how many lines…
nburk
  • 22,409
  • 18
  • 87
  • 132
91
votes
11 answers

UILabel font size?

I can't seem to modify the font size of a UILabel with the following code: itemTitle.font = [UIFont systemFontOfSize:25]; As i increase the number 25 to something greater, it seems to only add a top margin to the label, which consequently pushes…
John
  • 32,403
  • 80
  • 251
  • 422
89
votes
6 answers

UIButton with two lines of text in the title (numberOfLines=2)

I'm trying to make a UIButton that has two lines of text in its titleLabel. This is the code I'm using: UIButton *titleButton = [[UIButton alloc] initWithFrame:CGRectMake(15, 10, frame.size.width-100, 100)]; titleButton.titleLabel.font = [UIFont…
marketer
  • 41,507
  • 11
  • 37
  • 40
88
votes
8 answers

iOS: set font size of UILabel Programmatically

I'm trying to set the font size of a UILabel. No matter what value I put though the text size doesn't seem to change. Here's the code I'm using. [self setTitleLabel:[[UILabel alloc] initWithFrame:CGRectMake(320.0,0.0,428.0,50.0)]]; [[self…
LoneWolfPR
  • 3,978
  • 12
  • 48
  • 84
87
votes
13 answers

Custom installed font not displayed correctly in UILabel

I'm trying to use a Helvetica Neue Condensed font which I got from the Adobe Font Collection Pro Package. Unfortunately, it seems to draw incorrectly when I use it within a UILabel. The line height seems to be calculated correctly (I think), but…
MikeQ
  • 1,817
  • 3
  • 19
  • 27
85
votes
10 answers

How to set textColor of UILabel in Swift

When I try setting the color of a UILabel to the color of another UILabel using the code myLabel.textColor = otherLabel.textColor It doesn't change the color. When I use this code, however, myLabel.textColor = UIColor.redColor() It changes the…
kag359six
  • 1,693
  • 2
  • 16
  • 21
83
votes
6 answers

sizeWithFont method is deprecated. boundingRectWithSize returns an unexpected value

In iOS7, sizeWithFont is deprecated, so I am using boundingRectWithSize(which returns a CGRect value). My code: UIFont *fontText = [UIFont fontWithName:[AppHandlers zHandler].fontName size:16]; // you can use your font. CGSize…
Nirav Jain
  • 5,088
  • 5
  • 40
  • 61
83
votes
2 answers

UILineBreakModeWordWrap is deprecated

Here's my code: CGSize s = [string sizeWithFont:[UIFont systemFontOfSize:20] constrainedToSize:CGSizeMake(self.view.bounds.size.width - 40, CGFLOAT_MAX) // - 40 For cell padding …
Drakesinmoue
  • 895
  • 1
  • 6
  • 11
81
votes
6 answers

Animate UILabel text between two numbers?

I'm new to iPhone and Mac programming (developed for Windows before), and I've got a question: How do I animate the text property of an UILabel between two numbers, e.g. from 5 to 80 in an Ease-Out style? Is it possible with CoreAnimation? I have…
Markus Kasten
  • 1,170
  • 1
  • 10
  • 15
81
votes
9 answers

How do I locate the CGRect for a substring of text in a UILabel?

For a given NSRange, I'd like to find a CGRect in a UILabel that corresponds to the glyphs of that NSRange. For example, I'd like to find the CGRect that contains the word "dog" in the sentence "The quick brown fox jumps over the lazy dog." The…
bryanjclark
  • 6,247
  • 2
  • 35
  • 68
80
votes
3 answers

Pixel Width of the text in a UILabel

I need to draw a UILabel striked through. Therefore I subclassed UILabel and implemented it as follows: @implementation UIStrikedLabel - (void)drawTextInRect:(CGRect)rect{ [super drawTextInRect:rect]; CGContextRef context =…
Erik
  • 11,944
  • 18
  • 87
  • 126
78
votes
3 answers

Swift. UILabel text alignment

I create my UILabel in swift: let label = UILabel(frame: CGRect( x: 50, y: 50, width: 100, height: 50)) setting properties seems to be easy: label.textColor = UIColor.redColor() How to implement enum types like textAlignment? In Objective C it…
Thorax
  • 2,352
  • 1
  • 22
  • 27
77
votes
14 answers

How to calculate UILabel height dynamically?

I want to calculate number of lines and height of UILabel dynamically from given text for same.
Hitesh
  • 1,230
  • 1
  • 10
  • 12
76
votes
9 answers

Animating UILabel Font Size Change

I am currently making an application that uses a custom View Controller container. Multiple views are on the screen at one time and when one is tapped, the selected view controller animates to full screen. In doing so, the selected view controllers…
morcutt
  • 3,739
  • 8
  • 30
  • 47