Hello,
I want to change color of word when i tap in UITaxview just like in
InstaQuoteI write some code
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(textTapped:)];
[_textview addGestureRecognizer:tap];
- (void)textTapped:(UITapGestureRecognizer *)recognizer
{
UITextView *textView = (UITextView *)recognizer.view;
// Location of the tap in text-container coordinates
NSLayoutManager *layoutManager = textView.layoutManager;
CGPoint location = [recognizer locationInView:textView];
location.x -= textView.textContainerInset.left;
location.y -= textView.textContainerInset.top;
NSLog(@"location: %@", NSStringFromCGPoint(location));
NSLog(@"%@",[self getWordAtPosition:location inTextView:_lbl_test]);
//I got word which i tapped but How to change color of word which I tapped. I have little knowledge of NSMutableAttributedString. but didn't know how? can anyone suggest me what i do? }
-(NSString*)getWordAtPosition:(CGPoint)pos inTextView:(UITextView*)_tv
{
pos.y += _tv.contentOffset.y;
UITextPosition *tapPos = [_tv closestPositionToPoint:pos];
UITextRange * wr = [_tv.tokenizer rangeEnclosingPosition:tapPos withGranularity:UITextGranularityWord inDirection:UITextLayoutDirectionRight];
return [_tv textInRange:wr];
}