UILabel设置行高:
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:text];
NSMutableParagraphStyle * paragraphStyle = [[NSMutableParagraphStyle alloc] init];
[paragraphStylesetLineSpacing:8];
[attributedStringaddAttribute:NSParagraphStyleAttributeNamevalue:paragraphStylerange:NSMakeRange(0, [textlength])];
[_footLabsetAttributedText:attributedString];
计算内容高度:
NSDictionary *d = @{NSParagraphStyleAttributeName: paragraphStyle,NSFontAttributeName: [UIFont systemFontOfSize:15]};
CGRect rect = [text boundingRectWithSize:CGSizeMake(MAINSCREEN_WIDTH, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:d context:nil];
CGFloat h = ceilf(rect.size.height);
网友评论