Add gesture recognizer to your UITextView:
//bind gesture
[_yourTextView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:delegate action:@selector(didReceiveGestureOnText:)]];
And then just check which word is clicked in didReceiveGestureOnText with following code:
+(NSString*)getPressedWordWithRecognizer:(UIGestureRecognizer*)recognizer
{
//get view
UITextView *textView = (UITextView *)recognizer.view;
//get location
CGPoint location = [recognizer locationInView:textView];
UITextPosition *tapPosition = [textView closestPositionToPoint:location];
UITextRange *textRange = [textView.tokenizer rangeEnclosingPosition:tapPosition withGranularity:UITextGranularityWord inDirection:UITextLayoutDirectionRight];
//return string
return [textView textInRange:textRange];
}
EDIT
This is how your didReceiveGestureOnText method should look-like:
-(void)didReceiveGestureOnText:(UITapGestureRecognizer*)recognizer
{
//check if this is actual user
NSString* pressedWord = [delegate getPressedWordWithRecognizer:recognizer];
}
However this will led you in checking strings after all which is in really cool(as it's slow).
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…