NSMutableAttributedString *text2 = [[NSMutableAttributedString alloc] initWithString:model.reply];
//設置縮進、行距
NSMutableParagraphStyle *style2 = [[NSMutableParagraphStyle alloc] init];
// 對齊方式
style2.alignment = NSTextAlignmentJustified;
// 頭部縮進
style2.headIndent = 10.0f;
// 首行縮進
style2.firstLineHeadIndent = 10.0f;
// 尾部縮進
style2.tailIndent = -10.0f;
[text2 addAttribute:NSParagraphStyleAttributeName value:style2 range:NSMakeRange(0, model.reply.length)];
self.remark.attributedText = text2;
懶加載remark
-(UILabel *)remark{
if (_remark == nil) {
_remark = [[UILabel alloc] init];
_remark.font = FONT(FONT_BIG_SIZE);
_remark.textColor = C_MAIN_COLOR;
_remark.textAlignment = NSTextAlignmentJustified;
_remark.layer.masksToBounds = YES;
_remark.layer.cornerRadius = 5.f;
_remark.layer.borderColor = C_MAIN_COLOR.CGColor;
_remark.layer.borderWidth = 1.f;
_remark.backgroundColor = [C_MAIN_COLOR colorWithAlphaComponent:0.2f];
}
return _remark;
}
效果如下圖(其中remark事先設置了邊框和背景,還進行高度自適應)
IMG_3216.PNG