【问题标题】:Different colors in UITextViewUITextView中的不同颜色
【发布时间】:2013-02-12 00:04:18
【问题描述】:

我尝试在 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;

可能是属性不正确,你能告诉我是什么属性改变了文本的颜色吗?

【问题讨论】:

    标签: ios objective-c cocoa-touch nsstring


    【解决方案1】:

    尝试使用NSForegroundColorAttributeName 而不是kCTForegroundColorAttributeName

    NSAttributedString attribute keys

    【讨论】:

      猜你喜欢
      • 2018-09-27
      • 1970-01-01
      • 1970-01-01
      • 2014-07-20
      • 1970-01-01
      • 1970-01-01
      • 2014-10-01
      • 1970-01-01
      • 2011-10-31
      相关资源
      最近更新 更多