// 设置字间距
CGFloat spacing = 4.0;
[attributedString yy_setKern:@(spacing) range:NSMakeRange(0, attributedString.length)];
CGFloat spacing = 4.0;
[hintString yy_setKern:@(spacing) range:NSMakeRange(0, hintString.length)];
// 创建NSMutableParagraphStyle并设置行间距
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
paragraphStyle.lineSpacing = 4.0; // 设置行间距为10
// 将段落样式应用到整个字符串
[hintString yy_setParagraphStyle:paragraphStyle range:NSMakeRange(0, hintString.length)];
- (void)viewDidLoad {
[super viewDidLoad];
// 创建一个YYLabel
YYLabel *yyLabel = [[YYLabel alloc] initWithFrame:CGRectMake(20, 50, 300, 50)];
// 创建一个NSMutableAttributedString
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:@"这是一段测试文本"];
// 设置整体字体
attributedString.yy_font = [UIFont systemFontOfSize:18.0];
// 设置指定范围内的字体大小
UIFont *largeFont = [UIFont systemFontOfSize:24.0];
[attributedString yy_setFont:largeFont range:NSMakeRange(0, 5)];
// 设置字间距
CGFloat spacing = 4.0;
[attributedString yy_setKern:@(spacing) range:NSMakeRange(0, attributedString.length)];
// 创建NSMutableParagraphStyle并设置行间距
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
paragraphStyle.lineSpacing = 10.0; // 设置行间距为10
// 将段落样式应用到整个字符串
[attributedString yy_setParagraphStyle:paragraphStyle range:NSMakeRange(0, attributedString.length)];
// 设置YYLabel的属性文本
yyLabel.attributedText = attributedString;
// 将YYLabel添加到视图中
[self.view addSubview:yyLabel];
}