最佳答案
您可以通过编程方式实现这一点。使用 NSMutableAttributedString
NSMutableAttributedString *stringText = [[NSMutableAttributedString alloc] initWithString:@"This is awesome"];
//Green color for the first four characters.
[stringText addAttribute: NSForegroundColorAttributeName value: [UIColor greenColor] range: NSMakeRange(0, 4)];
// Sets the font color of last four characters to yellow.
[stringText addAttribute: NSForegroundColorAttributeName value: [UIColor yellowColor] range: NSMakeRange(14, 10)];
将此文本设置为您的 UITextView。它应该工作。还要确保文本是否动态更改,您需要充分注意 NSMakeRange。
关于ios - 在 Attributed TextView (Xcode) 中更改文本颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32637779/