設定首行縮排
阿新 • • 發佈:2019-02-11
主要使用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];
效果圖: