में टैप से शब्द प्राप्त करें मैं एक टैप से एक शब्द प्राप्त करने का प्रयास कर रहा हूं। निम्नलिखित कार्य sender
से UITextView
, वाक्य पर है।UITextView
- (IBAction)printWordSelected:(id)sender {
NSLog(@"Clicked");
CGPoint pos = [sender locationInView:self.view];
UITextView *_tv = sentence;
NSLog(@"Tap Gesture Coordinates: %.2f %.2f", pos.x, pos.y);
//eliminate scroll offset
pos.y += _tv.contentOffset.y;
//get location in text from textposition at point
UITextPosition *tapPos = [_tv closestPositionToPoint:pos];
//fetch the word at this position (or nil, if not available)
UITextRange * wr = [_tv.tokenizer rangeEnclosingPosition:tapPos withGranularity:UITextGranularityWord inDirection:UITextLayoutDirectionRight];
NSLog(@"WORD: %@", [_tv textInRange:wr]);
}
यह है कि मैं क्या पहले से ही है, लेकिन यह शून्य
के रूप में शब्द बाहर प्रिंट
** pos = [प्रेषक स्थान INView: _tv] ** को pos बदलने का प्रयास करें और फिर pos.y समायोजन को हटा दें। – rmaddy
ओह आप एक प्रतिभाशाली हैं! बहुत बहुत धन्यवाद!! – KBouldin9
कृपया जांचें http://stackoverflow.com/questions/8811909/getting-the-word-touched-in-a-uilabel-uitextview/21577829#21577829 – TheTiger