Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode 4.2 - UILabel Word Wrap

I know people have asked this question a bunch of times alrdy on Stack, but the usual answer of changing "Lines: 0" and selecting "Line Breaks: Word Wrap" just isn't fixing it for me.

I am using Xcode 4.2 with a Storyboard. I have placed a UILabel on a View Controller and resized it to cover most of the View. I have changed "Lines" value to 0 and "Line Breaks" value to Word Wrap.

I have tried \n in my string: @"This is my label text \n that's supposed to wrap."

Any ideas??

EDIT: I wasn't declaring any of the label's properties in my implementation file, only on the storyboard, so I have tried the following... But with no luck ;\ (font name and size and alignment work, but number of lines and break mode seem to do nothing.)

lblText.numberOfLines = 0;
lblText.font = [UIFont fontWithName:@"Helvetica" size:(15.0)];
lblText.lineBreakMode = UILineBreakModeWordWrap;
lblText.textAlignment = UITextAlignmentLeft;

like image 988
Solid I Avatar asked Jan 18 '12 21:01

Solid I


People also ask

How do you wrap text in UILabel?

If you set numberOfLines to 0 (and the label to word wrap), the label will automatically wrap and use as many of lines as needed. If you're editing a UILabel in IB, you can enter multiple lines of text by pressing option + return to get a line break - return alone will finish editing.


1 Answers

Try this

[lblText setFrame:CGRectMake(10, 21, 100, 250)];
lblText.text =@"This is my label text \n that's supposed to wrap.";
lblText.numberOfLines = 3;
lblText.font = [UIFont fontWithName:@"Helvetica" size:(15.0)];
lblText.lineBreakMode = UILineBreakModeWordWrap;
lblText.textAlignment = UITextAlignmentLeft;
like image 92
Anand Avatar answered Oct 18 '22 13:10

Anand