【发布时间】:2013-03-11 07:58:23
【问题描述】:
我想在 iOS 6 应用程序中创建多行标签。它在
这是我的代码:`
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运行
【问题讨论】:
-
请清除您的迁移,它在 iOS6 上有效但在 iOS5 上无效,这是您要问的吗?