2

Any way to have multiple lines of text in UILabel like in the UITextView?

I dont wish to use more than 1 label in the view.

Abhishek Bedi
  • 5,205
  • 2
  • 36
  • 62

7 Answers7

3

Just use this code in your Program

textLabel.lineBreakMode = UILineBreakModeWordWrap;
textLabel.numberOfLines = 0;
NANNAV
  • 4,875
  • 4
  • 32
  • 50
  • UILineBreakModeWordWrap is deprecated iOS 6 onwards. Instead of using it you can use NSLineBreakByWordWrapping. – Inoka May 16 '13 at 10:16
2

Yes this can be done by setting the numerOfLines property to the number of lines you want to display. Or set it to 0 if you just want to be able to add as many lines as you want.

rckoenes
  • 69,092
  • 8
  • 134
  • 166
1

You can check out this answer which has everything you want

You can also set Properties like numberoflines and linebreakMode

have look to documentation as well

Community
  • 1
  • 1
0

Use the numberOfLines property of UILabel and assign 0 for multiple lines.

Inoka
  • 664
  • 7
  • 16
0
textLabel.lineBreakMode = UILineBreakModeWordWrap;
textLabel.numberOfLines = 0;
Rushabh
  • 3,208
  • 5
  • 28
  • 51
0

set the lineBreakMode and numberOfLines property of UILabel and set the frame as see the multiple lines.

yourLabel.lineBreakMode = UILineBreakModeWordWrap;
yourLabel.numberOfLines = 0;
yourLabel.frame = CGRectMake(0,0,320,150);
DharaParekh
  • 1,730
  • 1
  • 10
  • 17
0

yes,this is possible in .xib file select your label you found Lines option set value that you want to i.e. line 3

if you creating label programmatic than

 lbl.numberOfLines = 0;

CGRect currentFrame = myLabel.frame;
CGSize max = CGSizeMake(lbl.frame.size.width, 500);
CGSize expected = [myString sizeWithFont:lbl.font constrainedToSize:max lineBreakMode:lbl.lineBreakMode]; 
currentFrame.size.height = expected.height;
lbl.frame = currentFrame;
user1548843
  • 670
  • 12
  • 20