【问题标题】:Multiline Label多行标签
【发布时间】: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 上无效,这是您要问的吗?

标签: iphone xcode ios6 uilabel


【解决方案1】:

不要为你的标签使用自动布局,取消勾选,代码工作正常,除此之外没有问题,希望对你有帮助!

【讨论】:

    【解决方案2】:

    你不需要最后一行代码。

    [descriptionLabel sizeToFit];
    

    【讨论】:

      猜你喜欢
      • 2020-11-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-07-29
      • 1970-01-01
      • 2011-06-20
      相关资源
      最近更新 更多