调整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];
效果图:
本文详细介绍了如何使用Objective-C编程语言调整UILabel组件的行间距,使其能够实现多行显示,并通过设置NSAttributedString和 NSMutableParagraphStyle来精确控制文本布局。
582

被折叠的 条评论
为什么被折叠?



