iOS 文字颜色
示例
您可以使用标签的textColor属性将文本颜色应用于标签的整个文本。
迅速
label.textColor = UIColor.redColor() label.textColor = UIColor(red: 64.0/255.0, green: 88.0/255.0, blue: 41.0/225.0, alpha: 1)
迅捷3
label.textColor = UIColor.red label.textColor = UIColor(red: 64.0/255.0, green: 88.0/255.0, blue: 41.0/225.0, alpha: 1)
目标C
label.textColor = [UIColor redColor]; label.textColor = [UIColor colorWithRed:64.0f/255.0f green:88.0f/255.0f blue:41.0f/255.0f alpha:1.0f];
将文本颜色应用于文本的一部分
您还可以使用以下命令更改文本各部分的文本颜色(或其他属性)NSAttributedString:
目标C
attributedString = [[NSMutableAttributedString alloc] initWithString:@"The grass is green; the sky is blue."]; [attributedString addAttribute: NSForegroundColorAttributeName value:[UIColor greenColor] range:NSMakeRange(13, 5)]; [attributedString addAttribute: NSForegroundColorAttributeName value:[UIColor blueColor] range:NSMakeRange(31, 4)]; label.attributedText = attributesString;
迅速
let attributedString = NSMutableAttributedString(string: "The grass is green; the sky is blue.") attributedString.addAttribute(NSForegroundColorAttributeName, value: UIColor.green(), range: NSRange(location: 13, length: 5)) attributedString.addAttribute(NSForegroundColorAttributeName, value: UIColor.blue(), range: NSRange(location: 31, length: 4)) label.attributedText = attributedString
热门推荐
1 泰迪狗狗如何训练
3 狗狗训练图
5 狗狗训练方法
6 训练狗狗不咬人
8 敏捷训练狗狗
10 训练狗狗吃饭
11 泰迪狗狗训练
12 狗狗从多大开始训练
13 狗狗训练学校费用
14 怎么去训练狗狗
15 狗狗训练狗狗
16 狗狗训练教程
17 训练狗狗装死
18 泰迪狗狗的训练方法