2013-08-07 27 views
1

我正在使用WUTextSuggestionController的#tag建議textview的應用程序,你可以在這裏檢查控制器https://github.com/YuAo/WUTextSuggestion。現在一切正常,當我開始使用#或@鍵入時,它會給出正確的結果。#tag建議UITextView與編輯時的屬性文本

現在我的問題是,如何更改uitextView中只有#tag vlaue的顏色,這意味着當我輸入Like 「#test for students」,然後只用#test以不同的顏色和剩餘的文本以常規顏色顯示。

任何幫助,任何小建議,歡迎。

回答

0

我希望可以幫你整理一下你的問題

-(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]; 
}