前言:
实现效果
// updateStr 为文字内容
NSMutableAttributedString *attrStr0 = [[NSMutableAttributedString alloc] initWithString:updateStr];
[attrStr0 addAttribute:NSForegroundColorAttributeName
value:[UIColor grayColor]
range:NSMakeRange(0, updateStr.length)];
[attrStr0 addAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:14]} range:NSMakeRange(0, updateStr.length)];
NSMutableParagraphStyle *paragraph = [[NSMutableParagraphStyle alloc] init];
paragraph.lineSpacing = 5;// 字体的行间距
paragraph.firstLineHeadIndent = 25.0f;//首行缩进
paragraph.alignment = NSTextAlignmentLeft;
[attrStr0 addAttribute:NSParagraphStyleAttributeName
value:paragraph
range:NSMakeRange(0, [updateStr length])];
UILabel *label0 = [[UILabel alloc] initWithFrame:CGRectMake(10, labels.wzp_MaxY+28, self.wzp_width-20, 0)];
//自动换行
label0.numberOfLines = 0;
//设置label的富文本
label0.attributedText = attrStr0;
//label高度自适应
[label0 sizeToFit];
[self addSubview:label0];
写文只为记事。