Xcode 4.2 - UILabel Word Wrap
Asked Answered
P

1

5

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;

Photosphere answered 18/1, 2012 at 21:9 Comment(0)
L
10

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;
Laity answered 19/1, 2012 at 4:14 Comment(2)
Works like a charm. setFrame:CGRectMake did the trick. For those who are puzzled by the numbers that follow CGRectMake, they stand for pixels: left, top, width, height. Thanks Happy!Photosphere
But what specifically about calling setFrame did the trick? Was your frame so large that it was extending horizontally beyond the bounds of the view, and as such no wrapping was occurring? Or is there something else about this specific frame that causes wrapping to occur in your case?Lollard

© 2022 - 2024 — McMap. All rights reserved.