// 将“文字”二字放大变成红色
NSString * AllStr = @"这是个测试文字";
NSRange WZRange = NSMakeRange(5, 2);
NSMutableAttributedString * wantStr = [[NSMutableAttributedString alloc] initWithString:AllStr];
[wantStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:20] range:WZRange];
[wantStr addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:WZRange];
UILabel * label = [[UILabel alloc] initWithFrame:CGRectMake(50, 80, 150, 50)];
label.textColor = [UIColor blackColor];
label.font = [UIFont systemFontOfSize:12];
label.attributedText = wantStr;
[self.view addSubview:label];
运行效果如下ios富文本功能/文字特性设置
最新推荐文章于 2025-06-26 09:00:00 发布