views:

2944

answers:

3

Hi, is there a way to have multiple lines of text in UILabel like in the UITextView or should I use the second one instead?

Thanks.

+12  A: 

I found a solution.

One just has to add the following code:

textLabel.lineBreakMode = UILineBreakModeWordWrap;
textLabel.numberOfLines = 0;
Ilya
A: 

I'm not sure how to write the text in interface builder. So just open up TextEdit and enter the text you want and copy and paste it into the text of the UILabel in interface builder.

Once that's done, open up the inspector and you should notice to the right of Alignment is "# lines" set that to 0, to make it check how many lines needed.

linead
+3  A: 

In IB, set number of lines to 0 (allows unlimited lines)

When typing within the text field using IB, use "alt-return" to insert a return and go to the next line (or you can copy in text already separated out by lines).

Kendall Helmstetter Gelner
[As he knowingly digs up a more-than-one-year-old thread …]One thing I sometimes wish I could do in IB is enter text *without* embedded line breaks, set UILineBreakModeWordWrap and numberOfLines = 0, and then have the label auto-size the height automagically, all the while still designing in IB.I'm thinking of the case where the view is resized to landscape, where line breaks in the label might be problematic. Or ... I could be misusing IB! Perhaps having the labels auto-size within IB causes more problems than it solves? (Also, you can't invoke sizeToFit at this point anyway.)
Joe D'Andrea