iOS multiline label in Interface builder

IosObjective CSwiftUilabelLine Breaks

Ios Problem Overview


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?

Ios Solutions


Solution 1 - Ios

You can use numberOfLines property which defines maximum number of lines a label can have. By default, it's 1. Setting it to 0 means the label will have unlimited lines.

You can do it in code:

textLabel.numberOfLines = 5 // for example

Or in Interface Builder:

Solution 2 - Ios

Hit Control+Enter to add a line in UILabel in Interface Builder/Storyboard.

Solution 3 - Ios

Thanks AppleVijay!

Also to call sizeToFit, like this:

label.lineBreakMode = UILineBreakModeWordWrap;
label.numberOfLines = 0;
[label sizeToFit];

The height will be automatically computed.

Solution 4 - Ios

set width of label as u needed small then use IB to set line breaks to word wrap

or use with code like this

I found a solution.

One just has to add the following code:

textLabel.lineBreakMode = NSLineBreakByWordWrapping;
textLabel.numberOfLines = 0;

Solution 5 - Ios

Set number of lines zero for dynamic text information, it will be useful when your text are varying.

Programatically (Swift 3)

var label = UILabel()
let stringValue = "iOS\nmultiline\nlabel\nin\nInterface\nbuilder"
label.text = stringValue
label.numberOfLines = 0 // Set 0, if number of lines not specified.
label.lineBreakMode = .byTruncatingTail // or .byWrappingWord
label.minimumScaleFactor = 0.8 . // It is not required but nice to have a minimum scale factor to fit text into label frame

Using Inetrface Builder

enter image description here

Note: It is not required to set Minimum Font Scale, but nice to have a minimum scale factor to fit text into label frame.

Solution 6 - Ios

Number of lines is visible in IB with Plain UILabels set lines field as 0 . It will create multiple lines as per the provided space to the label.

Solution 7 - Ios

In iOS7 (Xcode5) you shold set the lines of UILabel to 0 for unlimited multiple input in storyboard.
The most important is to set the height of the UILabel can hold the lines of input you are going to set.

Solution 8 - Ios

textLabel.lineBreakMode = UILineBreakModeWordWrap;

textLabel.numberOfLines = 0;

CGSize size =  [[[arrNewsFeed objectAtIndex:row] objectForKey:@"c"]  sizeWithFont:[UIFont systemFontOfSize:14.0]  constrainedToSize:CGSizeMake(188, CGFLOAT_MAX)
                                                                     lineBreakMode:NSLineBreakByTruncatingTail];

textLabel.frame = (CGRect){.origin = cell.lblNewsDescription.frame.origin, .size = size};

Solution 9 - Ios

If you set the numberOfLines property equal to 0, the label will automatically adjust to the required number of lines of the given text.

Solution 10 - Ios

I had been struggling with this for a long time. I just wanted my label text to appear on the second line. But whatever I do, it would just overflow the UILabel box. For me, changing the autoresizing in size inspector worked. Simple fix.

May be someone might find it helpful who is looking for something similar.

Solution 11 - Ios

For X-Code 7.2

  1. -- Select UILabel

  2. -- Attributes inspector

  3. -- Text - Select Attributed

After this you can see some more attribute you can add into you label, in which you can also find number of Lines. Which make your label multiline.

X-Code Image for a multiline UILabel

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionSamuli LehtonenView Question on Stackoverflow
Solution 1 - IosakashivskyyView Answer on Stackoverflow
Solution 2 - Iosuser1233894View Answer on Stackoverflow
Solution 3 - IosBogdanView Answer on Stackoverflow
Solution 4 - IosVijay-Apple-Dev.blogspot.comView Answer on Stackoverflow
Solution 5 - IosKrunalView Answer on Stackoverflow
Solution 6 - IossiddhantView Answer on Stackoverflow
Solution 7 - IosArtisanView Answer on Stackoverflow
Solution 8 - IosTanvi JainView Answer on Stackoverflow
Solution 9 - IosPablo MarrufoView Answer on Stackoverflow
Solution 10 - IosHarshal KarandeView Answer on Stackoverflow
Solution 11 - IoscodeCraftView Answer on Stackoverflow