I want to create multiline label in iOS 6 app. It runs successfully in < iOS V6.0 app, now i am using same code in iOS6 app but its not working.
Here is my code:`
descriptionLabel.font = [UIFont fontWithName:@"Arial" size:13];
text2 = [text2 stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
descriptionLabel.text=text2;
//here i calculate label height.
float messeglblHeight = [self calculateHeightOfTextFromWidth:text2 : [UIFont fontWithName:@"Arial" size:13] :280 :UILineBreakModeWordWrap];
[descriptionLabel setFrame:CGRectMake(descriptionLabel.frame.origin.x, descriptionLabel.frame.origin.y, 280, messeglblHeight)];
descriptionLabel.lineBreakMode = UILineBreakModeWordWrap;
descriptionLabel.numberOfLines = 0;
[descriptionLabel sizeToFit];
And i Calculate the label height from below function:
-(float) calculateHeightOfTextFromWidth:(NSString*) text: (UIFont*)withFont: (float)width :(UILineBreakMode)lineBreakMode
{
CGSize suggestedSize = [text sizeWithFont:withFont constrainedToSize:CGSizeMake(width, FLT_MAX) lineBreakMode:lineBreakMode];
return suggestedSize.height;
}
So please give me some suggestions.
PS: The code is in iOS 5, wants to run in iOS6

Dont use the auto layout for you label, make it uncheck, the code is working fine and there is no problem other than this, hope it helps for you!
You don't need last line of the code.
[descriptionLabel sizeToFit];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With