ios uilable如果一行如何去掉行间距
1个回答
展开全部
- (void)viewDidLoad {
[super viewDidLoad];
UILabel *dLabel = _desLab;
NSString *dLabelString = dLabel.text;
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:dLabelString];
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
//行间距
[paragraphStyle setLineSpacing:5.0];
//段落间距
[paragraphStyle setParagraphSpacing:10.0];
//第一行头缩进
[paragraphStyle setFirstLineHeadIndent:15.0];
//头部缩进
//[paragraphStyle setHeadIndent:15.0];
//尾部缩进
//[paragraphStyle setTailIndent:250.0];
//最小行高
//[paragraphStyle setMinimumLineHeight:20.0];
//最大行高
//[paragraphStyle setMaximumLineHeight:20.0];
[attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [dLabelString length])];
[dLabel setAttributedText:attributedString];
[dLabel setLineBreakMode:NSLineBreakByTruncatingTail];
CGRect dlRect = dLabel.frame;
[dLabel sizeToFit];
CGRect dlRectNew = dLabel.frame;
if(dlRectNew.size.height>dlRect.size.height){
dlRectNew.size.height = dlRect.size.height;
[dLabel setFrame:dlRectNew];
}
}
[super viewDidLoad];
UILabel *dLabel = _desLab;
NSString *dLabelString = dLabel.text;
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:dLabelString];
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
//行间距
[paragraphStyle setLineSpacing:5.0];
//段落间距
[paragraphStyle setParagraphSpacing:10.0];
//第一行头缩进
[paragraphStyle setFirstLineHeadIndent:15.0];
//头部缩进
//[paragraphStyle setHeadIndent:15.0];
//尾部缩进
//[paragraphStyle setTailIndent:250.0];
//最小行高
//[paragraphStyle setMinimumLineHeight:20.0];
//最大行高
//[paragraphStyle setMaximumLineHeight:20.0];
[attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [dLabelString length])];
[dLabel setAttributedText:attributedString];
[dLabel setLineBreakMode:NSLineBreakByTruncatingTail];
CGRect dlRect = dLabel.frame;
[dLabel sizeToFit];
CGRect dlRectNew = dLabel.frame;
if(dlRectNew.size.height>dlRect.size.height){
dlRectNew.size.height = dlRect.size.height;
[dLabel setFrame:dlRectNew];
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询