主要使用TextKit方法。
具体代码如下:
NSMutableParagraphStyle *paraStyle01 = [[NSMutableParagraphStyle alloc] init];
paraStyle01.alignment = NSTextAlignmentLeft; //对齐
paraStyle01.headIndent = 0.0f;//行首缩进
paraStyle01.firstLineHeadIndent = 24.0f;//首行缩进
NSAttributedString *attrText = [[NSAttributedString alloc] initWithString:@"首行缩进首行缩进首行缩进首行缩进首行缩进首行缩进首行缩进首行缩进首行缩进首行缩进首行缩进首行缩进首行缩进首行缩进首行缩进首行缩进首行缩进首行缩进首行缩进首行缩进首行缩进首行缩进首行缩进" attributes:@{ NSParagraphStyleAttributeName : paraStyle01}];
UILabel *_content = [[UILabel alloc] initWithFrame:CGRectMake(0,20, 200, 30)];
_content.numberOfLines=0;
_content.font = [UIFont systemFontOfSize:12];
_content.backgroundColor = [UIColor redColor];
_content.attributedText = attrText;
[self.view addSubview:_content];
效果图: