The goal of my question is making note app like iOS\'s. The point of iOS\'s note app is that they provide to user to use hyper link or phone number link or email address as
Above Answer in Swift 4:
tapGesture = UITapGestureRecognizer(target: self, action: #selector(self.textViewTapped(recognizer:)))
textView.addGestureRecognizer(tapGesture)
@objc func textViewTapped(recognizer: UITapGestureRecognizer) {
if recognizer.state == .ended {
textView.isEditable = true
textView.becomeFirstResponder()
let location = recognizer.location(in: textView)
if let position = textView.closestPosition(to: location) {
let uiTextRange = textView.textRange(from: position, to: position)
if let start = uiTextRange?.start, let end = uiTextRange?.end {
let loc = textView.offset(from: textView.beginningOfDocument, to: position)
let length = textView.offset(from: start, to: end)
textView.selectedRange = NSMakeRange(loc, length)
}
}
}
}
- (void) editTextRecognizerTabbed:(UITapGestureRecognizer *) aRecognizer
{
if (aRecognizer.state==UIGestureRecognizerStateEnded)
{
//Not sure if you need all this, but just carrying it forward from your code snippet
textview.editable = YES;
textview.dataDetectorTypes = UIDataDetectorTypeNone;
[textview becomeFirstResponder];
//Consider replacing self.view here with whatever view you want the point within
CGPoint point = [aRecognizer locationInView:self.view];
UITextPosition * position=[textView closestPositionToPoint:point];
[textView setSelectedTextRange:[textView textRangeFromPosition:position toPosition:position]];
}
}