SoFunction
Updated on 2025-04-12

UITextView implements a method that only allows link interaction but not allows selection of images

Detection link

As we all know, UITextVview can automatically detect links in text using the following methods:

let label = UITextView()
 = .link
 = false

If we use attributedString after we add Attachment, a selection (edited GR) will be triggered. If we only want the linked gr and not the selected gr, we can traverse and disable it. The method is as follows:

Portal: /questions/18962742/uitextview-link-detection-in-ios-7

Objective-C

NSArray *textViewGestureRecognizers = ;
NSMutableArray *mutableArrayOfGestureRecognizers = [[NSMutableArray alloc] init];
for (UIGestureRecognizer *gestureRecognizer in textViewGestureRecognizers) {
 if (![gestureRecognizer isKindOfClass:[UILongPressGestureRecognizer class]]) {
  [mutableArrayOfGestureRecognizers addObject:gestureRecognizer];
 } else {
  UILongPressGestureRecognizer *longPressGestureRecognizer = (UILongPressGestureRecognizer *)gestureRecognizer;
  if ( < 0.3) {
   [mutableArrayOfGestureRecognizers addObject:gestureRecognizer];
  }
 }
}
 = mutableArrayOfGestureRecognizers;

Summarize

The above is the entire content of this article. I hope the content of this article will be of some help to your study or work. If you have any questions, you can leave a message to communicate.