我有一个带有标签和大文字的应用程序。我尝试将标签的高度调整为适合这样的文本:
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];
但是当我实现此代码时,结果如下所示:
绿色是UILabel背景。
有什么问题?
PS除了字体大小不是13.为什么?
答案 0 :(得分:1)
如果文字太大,你应该真正使用TextView - 它是为它做的=)
答案 1 :(得分:1)
你确定“Helvetica Neue”是正确的吗?我不认为它会用不正确的字体大小合适。尝试:
[UIFont fontWithName:@"HelveticaNeue" size:13];