Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 689
Samuli Lehtonen Avatar asked Jul 02 '11 14:07

Samuli Lehtonen


3 Answers

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:

like image 87
akashivskyy Avatar answered Oct 23 '22 16:10

akashivskyy


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

like image 40
user1233894 Avatar answered Oct 23 '22 16:10

user1233894


Thanks AppleVijay!

Also to call sizeToFit, like this:

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

The height will be automatically computed.

like image 34
Bogdan Avatar answered Oct 23 '22 16:10

Bogdan