1.label設(shè)置行間距或者段間距 還有兩端對(duì)齊方式(label沒(méi)有該屬性)
2.label給指定字符串顯示指定的顏色讶请、字體大小畜挥。下劃線等。
代碼
//message
NSMutableAttributedString * attributedString = [[NSMutableAttributedString alloc] initWithString:_message];
//樣式
NSMutableParagraphStyle * paragraphStyle = [[NSMutableParagraphStyle alloc] init];
//設(shè)置label每行文字之間的行間距 paragraphStyle.lineSpacing=3;
//設(shè)置文字兩端對(duì)齊
paragraphStyle.alignment=NSTextAlignmentJustified;
NSDictionary * dic =@{
//這兩個(gè)一定要加哦。否則就沒(méi)效果啦
NSParagraphStyleAttributeName:paragraphStyle,
NSUnderlineStyleAttributeName:[NSNumber numberWithInteger:NSUnderlineStyleNone],
NSFontAttributeName:[UIFont systemFontOfSize:14]
};
//富文設(shè)置樣式
[attributedString setAttributes:dic range:NSMakeRange(0, attributedString.length)];
//設(shè)置
_labelmessage.attributedText = attributedString;
計(jì)算高度
CGSize titleSize = [mStr boundingRectWithSize:CGSizeMake(SCREEN_WIDTH - 16 * 2, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin context:nil].size;