+ (UILabel *)getLabelFrame:(UILabel *)label withLineSpace:(NSInteger)lineSpace withAttributedString:(NSString *)string
{
[label setNumberOfLines:0];
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:string];
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
[paragraphStyle setLineSpacing:lineSpace];//调整行间距
[attributedString addAttribute:NSFontAttributeName
value:label.font
range:NSMakeRange(0, string.length)];
[attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [string length])];
label.attributedText = attributedString;
CGSize size = [label.attributedText boundingRectWithSize:CGSizeMake(label.frame.size.width, 1000) options:NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading context:nil].size;
label.frame = CGRectMake(label.frame.origin.x, label.frame.origin.y, size.width, size.height);
return label;
}
原文地址:http://zqlicoder1314.blog.51cto.com/3014999/1586206