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的
請清除你的遷移,它是在iOS6上工作,但在iOS5上沒有,你想問什麼? – mangesh 2013-03-11 09:01:33