Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiline Label

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

like image 726
Prashant Chaudhari Avatar asked Apr 12 '26 17:04

Prashant Chaudhari


2 Answers

enter image description here

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!

like image 177
mangesh Avatar answered Apr 15 '26 07:04

mangesh


You don't need last line of the code.

[descriptionLabel sizeToFit];
like image 38
Pei Avatar answered Apr 15 '26 05:04

Pei



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!