2012-03-13 91 views
0

我有一个应用程序,标签和大文本。我试图适应标签的高度,文字是这样的:UILabel适合文本

UILabel *description = [[UILabel alloc] initWithFrame:CGRectMake(20, sizeInSpik, 275, 0)]; 
      description.text = spik.text; 
      description.adjustsFontSizeToFitWidth = NO; 
      description.autoresizingMask = UIViewAutoresizingFlexibleHeight; 
      [description setFont:[UIFont fontWithName:@"Helvetica Neu" size:13]]; 
      description.textColor = [UIColor blackColor]; 
      description.lineBreakMode = UILineBreakModeWordWrap; 
      description.numberOfLines = 0; 
      [description sizeToFit]; 

      // Set the height 
      CGSize maximumLabelSize1 = CGSizeMake(270,9999); 
      CGSize titleSize1 = [description.text sizeWithFont:description.font constrainedToSize:maximumLabelSize1 lineBreakMode:description.lineBreakMode]; 

      //Adjust the label the the new height 
      CGRect newFrame1 = description.frame; 
      newFrame1.size.height = titleSize1.height; 
      description.frame = newFrame1; 
      description.backgroundColor = [UIColor greenColor]; 

但是,当我实现这个代码的结果是这样的:

enter image description here

绿颜色的UILabel背景。

问题是什么?

PS此外字体大小isnt 13.为什么?

+0

你检查了titleSize1.height是否它不是9999? – Khal 2012-03-13 15:02:04

回答

1

确定“黑体NEU”是正确的?我不认为它会适当地与一个不正确的字体大小。尝试:

[UIFont fontWithName:@"HelveticaNeue" size:13];