Ajit
Ajit

Reputation: 47

#tag suggested UITextView with attributed text while editing

I am working on app in which i am using WUTextSuggestionController for #tag suggested textview you can check the controller here https://github.com/YuAo/WUTextSuggestion. Now everything works fine when I start typeing with # or @ ,it gives the right result.

Now my question is,how to change the color of only #tag vlaue in uitextView that means when I type Like "#test for students",then only #test in different color and remaining text in a regular color.

Any help,any small suggestions are welcome.

Upvotes: 1

Views: 1262

Answers (1)

Romance
Romance

Reputation: 1414

I hope it may be help you and sort out your problem

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

Upvotes: 0

Related Questions