持续更新中......
设置label行数为0
[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;
获取label bounds
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); [label sizeToFit];