【问题标题】:UITextView clear attributedText before setting new textUITextView 在设置新文本之前清除属性文本
【发布时间】:2013-07-01 14:05:28
【问题描述】:

您好,我正在尝试替换 UITextView 子类的属性文本。我想更改文本的颜色。为此,使用以下代码:

AMR_ANSIEscapeHelper *ansiEscapeHelper = [[AMR_ANSIEscapeHelper alloc] init];
    [ansiEscapeHelper setDefaultStringColor:[receiveView.highlightColor objectForKey:@"text"]];
    NSMutableAttributedString *resultString = [receiveView.attributedText copy];

    [receiveView setAttributedText:[ansiEscapeHelper attributedStringWithANSIEscapedString:[ansiEscapeHelper ansiEscapedStringWithAttributedString:resultString]]];

问题是:文本没有被替换;它似乎只是添加了另一层文字,使文字颜色很奇怪。在我第二次设置属性文本之前是否需要声明一些清除?

它的外观如下:(文字不应为黑色、深绿色和红色)

)

【问题讨论】:

    标签: ios uitextview uicolor nsattributedstring


    【解决方案1】:

    子类 RegexHighlightView 包含另一种为文本着色的方法,因此为字体绘制了多种颜色!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-10-19
      • 1970-01-01
      • 1970-01-01
      • 2013-10-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多