UILabel text doesn't word wrap

Posted by iFloh on Stack Overflow See other posts from Stack Overflow or by iFloh
Published on 2010-04-28T13:37:30Z Indexed on 2010/04/28 13:43 UTC
Read the original article Hit count: 659

Filed under:
|
|

Hi, I have a long text string (including \n newline charactersthat I feed into a UILabel for display. The UILabel is dynamically setup to provide sufficient space foor the text.

My code looks like this:

myText = [NSString stringWithFormat:@"%@some text: %@ \n \n %@", myText, moreText1, moreText2];
NSLog(@"%@", myText);
myLabelSize = [vLabelText sizeWithFont:[UIFont fontWithName:@"Helvetica" size:(15.0)] constrainedToSize:cMaxLabelSize lineBreakMode:UILineBreakModeWordWrap];

UILabel *lBody = [[UILabel alloc] initWithFrame:CGRectMake(cFromLeft, vFromTop, vLabelSize.width, vLabelSize.height)];
lBody.font = [UIFont fontWithName:@"Helvetica" size:(15.0)];
lBody.lineBreakMode = UILineBreakModeWordWrap;
lBody.textAlignment =  UITextAlignmentLeft;
lBody.backgroundColor = [UIColor cyanColor];
[myScrollView addSubview:lBody];
lBody.text = vLabelText;

My problem is that the text does not wrap, but truncates after the first line. The \n newlines are ignored.

any ideas?

© Stack Overflow or respective owner

Related posts about objective-c

Related posts about iphone