iOS小知识点-多行UILabel首行缩进
2020-08-08 本文已影响0人
流云_henry
image.png
对于这种多行UILabel,Lab前面又有其他控件,我们该如何布局呢。其实很简单,UILabel的布局依旧从最左侧开始布局,只是我们需要对UILabel作出部分处理。
NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init];
style.firstLineHeadIndent = 25 + nickWidth;//v10Lable+昵称Lable的宽度
NSMutableAttributedString * attri = [[NSMutableAttributedString alloc]initWithString:self.messageLab.text];
[attri addAttribute:NSParagraphStyleAttributeName value:style range:NSMakeRange(0, self.messageLab.text.length)];
[self.messageLab setAttributedText:attri];
通过富文本,我们设置首行的headIndent就可以达到我们要的效果了