【问题标题】:#tag suggested UITextView with attributed text while editing#tag 在编辑时建议带有属性文本的 UITextView
【发布时间】:2013-08-08 19:27:24
【问题描述】:

我正在开发应用程序,在该应用程序中我使用 WUTextSuggestionController 获取#tag 建议的文本视图,您可以在此处查看控制器 https://github.com/YuAo/WUTextSuggestion。现在,当我开始使用 # 或 @ 输入时,一切正常,它给出了正确的结果。

现在我的问题是,如何在 uitextView 中仅更改 #tag vlaue 的颜色,这意味着当我键入 Like 时 “#test for students”,然后只用不同的颜色进行#test,其余的文字用常规颜色。

欢迎任何帮助,任何小的建议。

【问题讨论】:

    标签: ios tags uitextview autosuggest textcolor


    【解决方案1】:

    希望对你有帮助,解决你的问题

    -(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{
    {
    
    NSMutableAttributedString * string = [[NSMutableAttributedString alloc]initWithString:textView.text];
    
    if([text isEqualToString:@"#"]){
                NSRange range=[textView.text rangeOfString:text];
                [string addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:range];           
        }
        [self.text setAttributedText:string];
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-02-24
      • 2013-03-28
      • 1970-01-01
      • 1970-01-01
      • 2018-12-23
      • 2023-03-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多