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.

uilabel
Filter by
Sorted by
Tagged with
2340 votes
51 answers
764k views

Vertically align text to top within a UILabel

I have a UILabel with space for two lines of text. Sometimes, when the text is too short, this text is displayed in the vertical center of the label. How do I vertically align the text to always be ...
Stefan's user avatar
  • 28.9k
482 votes
26 answers
416k views

Multiple lines of text in UILabel

Is there a way to have multiple lines of text in UILabel like in the UITextView or should I use the second one instead?
Ilya Suzdalnitski's user avatar
377 votes
31 answers
432k views

How do I make an attributed string using Swift?

I am trying to make a simple Coffee Calculator. I need to display the amount of coffee in grams. The "g" symbol for grams needs to be attached to my UILabel that I am using to display the amount. The ...
dcbenji's user avatar
  • 4,648
334 votes
38 answers
318k views

UILabel text margin [duplicate]

I'm looking to set the left inset/margin of a UILabel and can't find a method to do so. The label has a background set so just changing its origin won't do the trick. It would be ideal to inset the ...
Ljdawson's user avatar
  • 12.2k
327 votes
34 answers
307k views

Adjust UILabel height depending on the text

Consider I have the following text in a UILabel (a long line of dynamic text): Since the alien army vastly outnumbers the team, players must use the post-apocalyptic world to their advantage, such ...
Mustafa's user avatar
  • 20.6k
316 votes
21 answers
281k views

How to control the line spacing in UILabel

Is it possible to reduce the gap between text, when put in multiple lines in a UILabel? We can set the frame, font size and number of lines. I want to reduce the gap between the two lines in that ...
Abhinav's user avatar
  • 38k
301 votes
21 answers
353k views

How do I change the font size of a UILabel in Swift?

label.font.pointSize is read-only, so I'm not sure how to change it.
Jay's user avatar
  • 9,514
300 votes
35 answers
308k views

Create tap-able "links" in the NSAttributedString of a UILabel?

Many applications have text and in this text are web hyperlinks in rounded rect. When I click them UIWebView opens. What puzzles me is that they often have custom links, for example if words starts ...
Lope's user avatar
  • 5,397
291 votes
21 answers
315k views

How to add line break for UILabel?

Let see that I have a string look like this: NSString *longStr = @"AAAAA\nBBBBB\nCCCCC"; How do I make it so that the UILabel display the message like this AAAAA BBBBB CCCCC I don't ...
Thang Pham's user avatar
  • 38.5k
265 votes
38 answers
361k views

Adding space/padding to a UILabel

I have a UILabel where I want to add space in the top and in the bottom. With the minimum height in constraints, I've modified it to: To do this I've used: override func drawTextInRect(rect: CGRect) {...
Annachiara's user avatar
  • 2,677
262 votes
15 answers
161k views

Bold & Non-Bold Text In A Single UILabel?

How would it be possible to include both bold and non-bold text in a uiLabel? I'd rather not use a UIWebView.. I've also read this may be possible using NSAttributedString but I have no idea how to ...
DomMaiocchi's user avatar
  • 2,747
245 votes
10 answers
211k views

UILabel Align Text to center

How do I align text in UILabel?
vivianaranha's user avatar
  • 2,781
225 votes
14 answers
189k views

Figure out size of UILabel based on String in Swift

I am trying to calculate the height of a UILabel based on different String lengths. func calculateContentHeight() -> CGFloat{ var maxLabelSize: CGSize = CGSizeMake(frame.size.width - 48, ...
Cody Weaver's user avatar
  • 4,826
213 votes
12 answers
268k views

Dynamically changing font size of UILabel

I currently have a UILabel: factLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 100, 280, 100)]; factLabel.text = @"some text some text some text some text"; factLabel.backgroundColor = [...
CodeGuy's user avatar
  • 28.7k
211 votes
22 answers
122k views

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 ...
Boon's user avatar
  • 41k
198 votes
8 answers
85k views

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 ...
mverderese's user avatar
  • 5,324
191 votes
8 answers
129k views

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 ...
James Harpe's user avatar
  • 4,345
173 votes
12 answers
163k views

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 ...
Daniele B's user avatar
  • 20.2k
160 votes
5 answers
114k views

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 ...
Codezy's user avatar
  • 5,560
159 votes
13 answers
97k views

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 ...
circuitlego's user avatar
  • 3,489
158 votes
14 answers
125k views

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 ...
Joo Park's user avatar
  • 3,145
155 votes
19 answers
162k views

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's user avatar
  • 1,748
155 votes
15 answers
259k views

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 ...
wayneh's user avatar
  • 4,393
154 votes
16 answers
138k views

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's user avatar
  • 4,123
154 votes
9 answers
136k views

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's user avatar
  • 41k
148 votes
8 answers
143k views

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's user avatar
  • 60.5k
148 votes
21 answers
100k views

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's user avatar
  • 3,945
144 votes
16 answers
177k views

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's user avatar
  • 38.9k
143 votes
11 answers
55k views

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 = [[...
Sean Danzeiser's user avatar
143 votes
11 answers
105k views

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's user avatar
133 votes
12 answers
268k views

How to create UILabel programmatically using Swift?

How do I create a UILabel programmatically using Swift in Xcode 6? I have started with a new "Single View Application" in Xcode 6 and selected Swift for this project. I have my files AppDelegate....
Akhtar's user avatar
  • 3,182
133 votes
18 answers
203k views

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:...
TheBurgerShot's user avatar
126 votes
23 answers
72k views

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 ...
Randall's user avatar
  • 14.8k
124 votes
13 answers
160k views

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 ...
Sneha's user avatar
  • 2,218
121 votes
4 answers
59k views

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 ...
Padin215's user avatar
  • 7,484
121 votes
10 answers
114k views

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's user avatar
  • 15.9k
117 votes
20 answers
111k views

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's user avatar
  • 1,171
113 votes
17 answers
128k views

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 ...
Justin Rose's user avatar
  • 1,175
112 votes
26 answers
235k views

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 ...
Mrunal's user avatar
  • 14.1k
110 votes
2 answers
186k views

Setting UILabel text to bold [duplicate]

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's user avatar
  • 2,972
108 votes
12 answers
83k views

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's user avatar
  • 7,098
107 votes
4 answers
99k views

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;...
wfbarksdale's user avatar
  • 7,546
103 votes
10 answers
105k views

Set UILabel line spacing

How can I modify the gap between lines (line spacing) in a multiline UILabel?
Matrix's user avatar
  • 7,527
101 votes
12 answers
77k views

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 ...
Happy's user avatar
  • 1,013
94 votes
21 answers
133k views

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 ...
semix's user avatar
  • 959
92 votes
9 answers
36k views

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 ...
Hooman Ahmadi's user avatar
91 votes
17 answers
89k views

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 ...
nburk's user avatar
  • 22.6k
91 votes
11 answers
127k views

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 ...
learningtech's user avatar
89 votes
6 answers
72k views

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, ...
marketer's user avatar
  • 42.5k
88 votes
8 answers
164k views

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:...
LoneWolfPR's user avatar
  • 4,030

1
2 3 4 5
142