NSMutableAttributedString *text = [[NSMutableAttributedString alloc] initWithString:str];
NSMutableParagraphStyle *muStyle = [[NSMutableParagraphStyle alloc] init];
CGFloat width = [UIScreen mainScreen].bounds.size.width;
if ([text.string isMoreThanOneLineWithSize:CGSizeMake(width-40-20-20, CGFLOAT_MAX) font:[UIFont systemFontOfSize:13.0] lineSpaceing:5.0]) {
muStyle.lineSpacing = 5.0;//设置行间距离
}else{
muStyle.lineSpacing = CGFLOAT_MIN;//设置行间距离
}
[text addAttribute:NSParagraphStyleAttributeName value:muStyle range:NSMakeRange(0, text.length)];
[text addAttribute:NSForegroundColorAttributeName
value:[UIColor orangeColor]
range:NSMakeRange(0, model.nickname.length)];
// [text addAttribute:NSForegroundColorAttributeName
// value:[UIColor orangeColor]
// range:NSMakeRange(model.nickname.length + 2, model.nickname.length)];
self.contentLabel.attributedText = text;