iOS _ UILabel 调整行间距

来源:互联网 发布:数据库阶段的特点 编辑:程序博客网 时间:2024/06/10 08:58

调整UILabel 的行间距

UILabel *headerBriefText = [[UILabel alloc] initWithFrame:(CGRectMake(10, 82, 350, 200))];
headerBriefText.text = @"冒险热血冒险热血冒险热血冒险热血冒险热血冒险热血,冒险热血冒险热血冒险热血冒险热血,冒险热血冒险热血冒险热血冒险热血,冒险热血冒险热血...";
headerBriefText.backgroundColor = [UIColor redColor];
headerBriefText.textColor = [UIColor orangeColor];
headerBriefText.font = [UIFont systemFontOfSize:18];
headerBriefText.numberOfLines = 0;
// 调整行间距
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:headerBriefText.text];
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
[paragraphStyle setLineSpacing:3];
[attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [headerBriefText.text length])];
headerBriefText.attributedText = attributedString;
[headerBriefText sizeToFit];
[self.view addSubview:headerBriefText];

效果图:
这里写图片描述

0 0
原创粉丝点击