iOS 修改label中文字的行间距

谁说我不能喝 提交于 2020-01-11 03:57:08
UILabel *label = [[UILabel alloc] init];
label.font = [UIFont systemFontOfSize:17];
label.textColor = [UIColor clackColor];
label.numberOfLines = 2;
label.text = @"333333333333333333333333333333";
[view addSubview:label];

NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:label.text];
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
[paragraphStyle setLineSpacing:7.0f];//设置行间距
[attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, label.text.length)];
label.attributedText = attributedString;
CGSize size = CGSizeMake(view.frame.size.width - 50, 41);
label.frame = CGRectMake(25, 25, [label sizeThatFits:size].width, [label sizeThatFits:size].height);

 

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!