2013-03-11 152 views
3

我想在iOS 6应用程序中创建多行标签。它在< iOS V6.0应用程序中成功运行,现在我在iOS6应用程序中使用相同的代码,但它不起作用。多行标签

这里是我的代码:`

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]; 

而且我从下面函数计算标签的高度:

-(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; 
} 

所以,请给我一些建议。

PS:该代码是iOS 5中,要在iOS6的

+1

请清除你的迁移,它是在iOS6上工作,但在iOS5上没有,你想问什么? – mangesh 2013-03-11 09:01:33

回答

3

enter image description here

不要使用自动布局你的标签,使其取消,代码工作正常,并没有比这个其他没有问题的,希望它可以帮助你!

2

跑你不需要的代码的最后一行。

[descriptionLabel sizeToFit];