1.label设置行间距或者段间距 还有两端对齐方式(label没有该属性)
2.label给指定字符串显示指定的颜色、字体大小。下划线等。
代码
//message
NSMutableAttributedString * attributedString = [[NSMutableAttributedString alloc] initWithString:_message];
//样式
NSMutableParagraphStyle * paragraphStyle = [[NSMutableParagraphStyle alloc] init];
//设置label每行文字之间的行间距 paragraphStyle.lineSpacing=3;
//设置文字两端对齐
paragraphStyle.alignment=NSTextAlignmentJustified;
NSDictionary * dic =@{
//这两个一定要加哦。否则就没效果啦
NSParagraphStyleAttributeName:paragraphStyle,
NSUnderlineStyleAttributeName:[NSNumber numberWithInteger:NSUnderlineStyleNone],
NSFontAttributeName:[UIFont systemFontOfSize:14]
};
//富文设置样式
[attributedString setAttributes:dic range:NSMakeRange(0, attributedString.length)];
//设置
_labelmessage.attributedText = attributedString;
计算高度
CGSize titleSize = [mStr boundingRectWithSize:CGSizeMake(SCREEN_WIDTH - 16 * 2, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin context:nil].size;
网友评论