gpt4 book ai didi

ios - UITextView中的不同颜色

转载 作者:行者123 更新时间:2023-12-01 19:13:34 26 4
gpt4 key购买 nike

我尝试在UITextView中添加具有不同颜色的字符串。我写了这段代码

NSMutableAttributedString* attString =
[[NSMutableAttributedString alloc]initWithString:view.text]; //view is my UITextView
[attString addAttribute:(NSString*)kCTForegroundColorAttributeName
value:[UIColor greenColor]
range:(NSRange){attString.length-8, 8}];
view.attributedText = attString;

可能是属性不正确,您能告诉我什么属性会更改文本的颜色吗?

最佳答案

尝试使用NSForegroundColorAttributeName而不是kCTForegroundColorAttributeName

NSAttributedString attribute keys

关于ios - UITextView中的不同颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14823280/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com