UILabel* contentLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 100, self.view.frame.size.width, 200)];
contentLabel.backgroundColor = [UIColor redColor];
contentLabel.numberOfLines = 0;
[self.view addSubview:contentLabel];
NSString *_test = @"首行缩进根据字体大小自动调整间个据字" ;
NSMutableParagraphStyle *paraStyle01 = [[NSMutableParagraphStyle alloc] init];
paraStyle01.alignment = NSTextAlignmentLeft; //对齐
paraStyle01.headIndent = 0.0f;//行首缩进
//参数:(字体大小17号字乘以2,34f即首行空出两个字符)
CGFloat emptylen = contentLabel.font.pointSize * 10.0;
paraStyle01.firstLineHeadIndent = emptylen;//首行缩进
paraStyle01.tailIndent = 0.0f;//行尾缩进
paraStyle01.lineSpacing = 2.0f;//行间距
NSAttributedString *attrText = [[NSAttributedString alloc] initWithString:_test attributes:@{NSParagraphStyleAttributeName:paraStyle01}];
contentLabel.attributedText = attrText;
触发条件:firstLineHeadIndent一定要足够大,文字刚好展示一行多几个字,就会出现如下图,文字显示不全的问题。哪位路过的大神帮忙解决一下哈,谢谢!!!
网友评论