views:

260

answers:

1

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?

+2  A: 

Just found the problem, my numberOfLines was still at 1. After setting it to 0 it worked just fine.

iFloh
Shoot.. you beat me to it... I had that exact problem and knew when I read your title that I had your solution.
Michael