You cannot assign a binding gesture to a specific row in a regular UITextView. You can probably set dataDetectorTypes for a UITextView.
textview.dataDetectorTypes = UIDataDetectorTypeAll;
If you want to detect only URLs, you can assign
textview.dataDetectorTypes = UIDataDetectorTypeLink;
For more information, see the documentation: DataTypes UIKit Data Reference . Also check out the UITextView Documentation
Update:
Based on your comment, check the following:
- (void)tapResponse:(UITapGestureRecognizer *)recognizer { CGPoint location = [recognizer locationInView:_textView]; NSLog(@"Tap Gesture Coordinates: %.2f %.2f", location.x, location.y); NSString *tappedSentence = [self lineAtPosition:CGPointMake(location.x, location.y)];
From this use:
- (NSString *)lineAtPosition:(CGPoint)position { //eliminate scroll offset position.y += _textView.contentOffset.y; //get location in text from textposition at point UITextPosition *tapPosition = [_textView closestPositionToPoint:position]; //fetch the word at this position (or nil, if not available) UITextRange *textRange = [_textView.tokenizer rangeEnclosingPosition:tapPosition withGranularity:UITextGranularitySentence inDirection:UITextLayoutDirectionRight]; return [_textView textInRange:textRange]; }
You can try with details like UITextGranularitySentence, UITextGranularityLine, etc. Here's the documentation .
iDev Feb 22 '13 at 23:04 2013-02-22 23:04
source share