UILabel首行缩进

今天在开发群里看到有人问如何做首行缩进,想起以前自己写过,很简单,代码放出来做个记录吧。

- (void)UILabel:(UILabel *)label SetText:(NSString *)labelText {

    NSMutableAttributedString *text = [[NSMutableAttributedString alloc]initWithString:labelText];

    NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init];
    style.headIndent = 15;//每一行行缩进
    style.firstLineHeadIndent = 20;首行缩进

    [text addAttribute:NSParagraphStyleAttributeName value:style range:NSMakeRange(0, text.length)];
    label.attributedText = text;

}