富文本的简单运用,可以改变文字的字体 颜色
UILabel *testLabel = [[UILabel alloc]initWithFrame:CGRectMake(50, 300, 220, 30)];
testLabel.backgroundColor = [UIColor lightGrayColor];
testLabel.textAlignment = NSTextAlignmentCenter;
NSMutableAttributedString *attributedStr = [[NSMutableAttributedString alloc]initWithString:@"测试一下富文本"];
[attributedStr addAttribute:NSFontAttributeName
value:[UIFont systemFontOfSize:26.0]
range:NSMakeRange(2, 3)];
[attributedStr addAttribute:NSForegroundColorAttributeName
value:[UIColor redColor]
range:NSMakeRange(2, 2)];
testLabel.attributedText = attributedStr;
[self.view addSubview:testLabel];
本文介绍了一个使用Objective-C设置富文本样式的示例,包括如何更改文本的颜色和字体大小等属性。
2204

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



