iOS _ UILabel 调整行间距

调整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];

效果图:
iOS _ UILabel 调整行间距_第1张图片

你可能感兴趣的:(UI控件)