很多时候我们需要根据文本的大小来定义label的高度:那么如何计算文本的大小呢:
如下:
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 375, 300)];
label.text = @"说大声的撒 爱上爱上爱上";
label.numberOfLines = 0;
label.textColor = [UIColor orangeColor];
[label release];
NSMutableDictionary *dic= [NSMutableDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:17], NSFontAttributeName, nil];
CGRect rect = [label.text boundingRectWithSize:CGSizeMake(375, 1000) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
label.frame = CGRectMake(10, 0, 355, rect.size.height + 20);