【iOS】首行缩进两个字符

时间:2022-09-23 06:24:32
NSString *_test  =  @"首行缩进根据字体大小自动调整 间隔可自定根据需求随意改变。。。。。。。" ;  
NSMutableParagraphStyle *paraStyle01 = [[NSMutableParagraphStyle alloc] init];
paraStyle01.alignment = NSTextAlignmentLeft; //对齐
paraStyle01.headIndent = 0.0f;//行首缩进
//参数:(字体大小17号字乘以2,34f即首行空出两个字符)
CGFloat emptylen = self.contentLabel.font.pointSize * 2;
paraStyle01.firstLineHeadIndent = emptylen;//首行缩进
paraStyle01.tailIndent = 0.0f;//行尾缩进
paraStyle01.lineSpacing = 2.0f;//行间距

NSAttributedString *attrText = [[NSAttributedString alloc] initWithString:_test attributes:@{NSParagraphStyleAttributeName:paraStyle01}];

self.contentLabel.attributedText = attrText;

原文地址

http://blog.csdn.net/leemin_ios/article/details/52045387