UILabel实现文字缩进
2016-05-09 本文已影响2071人
lancely
利用 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;