利用 NSMutableParagraphStyle
实现文字缩进
NSMutableParagraphStyle *style = [[NSParagraphStyle defaultParagraphStyle] mutableCopy]; // 对齐方式 style.alignment = NSTextAlignmentJustified; // 首行缩进 style.firstLineHeadIndent = 10.0f; // 头部缩进 style.headIndent = 10.0f; // 尾部缩进 style.tailIndent = -10.0f; NSAttributedString *attrText = [[NSAttributedString alloc] initWithString:title attributes:@{ NSParagraphStyleAttributeName : style}]; UILabel *label = [[UILabel alloc] initWithFrame:someFrame]; label.numberOfLines = 0; label.attributedText = attrText;
来源:https://www.cnblogs.com/lancely/p/5782774.html