UILabel实现文字缩进

利用 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;

你可能感兴趣的:(UILabel实现文字缩进)