Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITextView detect link with editable property to true

I have searched a lot for how to detect link in UITextView with editable property set to true, but didn't find any solution. All solutions suggest to set editable to NO, but by requirement I can't set editable to NO.

like image 650
Raj Aggrawal Avatar asked Jul 21 '16 06:07

Raj Aggrawal


1 Answers

Unfortunately you cannot have an editable UITextView with clickable links.

But you can try this code it might work. I get this from one tutorial: http://www.ama-dev.com/editable-uitextview-with-link-detection/

UITapGestureRecognizer *recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(editTextRecognizerTabbed:)]; 
recognizer.delegate = self;
recognizer.numberOfTapsRequired = 1;
[self.textViewNotes addGestureRecognizer:recognizer];

- (void) editTextRecognizerTabbed:(UITapGestureRecognizer *) aRecognizer; 
{
    self.textViewNotes.dataDetectorTypes = UIDataDetectorTypeNone; 
    self.textViewNotes.editable = YES;
    [self.textViewNotes becomeFirstResponder];
}

- (void)textViewDidEndEditing:(UITextView *)textView;
{ 
    self.textViewNotes.editable = NO;
    self.textViewNotes.dataDetectorTypes = UIDataDetectorTypeAll;
}
like image 176
Pranav Avatar answered Nov 04 '22 04:11

Pranav