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.redlabel.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
以上是 iOS 文字颜色 的全部内容, 来源链接: utcz.com/z/315775.html