I'm trying to get the correct height for a label using sizeWithFont, but it fails to return the correct height for this specific case.
UILabel* label = [[UILabel alloc] init];
[label setText:@"Finally made it to the gym now !! Lorem ipsum dolor sit amet"];
[label setFont:[UIFont fontWithName:@"Avenir-Light" size:16.0]];
label.lineBreakMode = NSLineBreakByTruncatingTail;
label.numberOfLines = 0;
CGSize size = [label.text sizeWithFont:label.font constrainedToSize:CGSizeMake(220, 99999) lineBreakMode:label.lineBreakMode];
[label setFrame:CGRectMake(0, 50, size.width , size.height)];
[self.view addSubview:label];
The text is suppose to go to 3 line, but it gets cutoff at 2. I believe it has to do with the fact that the UILabel groups the "now !!" as a single word where the sizeWithFont calculates the height by splitting "now" and "!!" as two separate words. I can only produce this in iOS 7, it seems to work fine in iOS 6. Any solution to this problem is greatly appreciated. Thanks!