Detect Character Tapped in UITextView

前端 未结 1 447
南方客
南方客 2021-01-03 15:44

I\'m using the below code to detect words tapped in a UITextView. This works fine, but I want to detect some special characters, like a ?. ? doesn\

相关标签:
1条回答
  • 2021-01-03 16:01

    This code worked for me on iOS 6:

        - (void)tappedTextView:(UITapGestureRecognizer *)recognizer {
            UITextView *textView = (UITextView *)recognizer.view;
            CGPoint location = [recognizer locationInView:textView];
            UITextPosition *tapPosition = [textView closestPositionToPoint:location];
            UITextRange *textRange = [textView.tokenizer rangeEnclosingPosition:tapPosition withGranularity:UITextGranularityCharacter inDirection:UITextLayoutDirectionRight];        
            NSString *character = [textView textInRange:textRange];
            NSLog(@"%@", character);
        }
    
    0 讨论(0)
提交回复
热议问题