修改一个Label上字体的大小(富文本)

时间:2023-03-10 05:41:21
修改一个Label上字体的大小(富文本)

修改一个Label上字体的大小(富文本)

假如修改上面的Label上价格30000的大小,那么需要用到富文本

上代码

// 字符串30000

NSString * priceNumber = @"30000";

[priceNumber length];

NSLog(@"%lu",(unsigned long)[priceNumber length]);

_price = [[UILabel alloc] initWithFrame:CGRectMake(0,100,200,100)];

NSMutableAttributedString *attriString = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"¥%@/人",priceNumber]];

[attriString addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:25] range:NSMakeRange(1, [priceNumber length])];

_price.attributedText = attriString;

[self.view addSubview:_price];