0

I have a UITextView with attributed text with multiple link's and those links have individual values for the keys and those links have click action on it.

When I am long-tapping on the link text and moving, I am able to see the value give to "NSAttributedString.Key.link". Either I have to disable the long-fess gesture or hide the value for "NSAttributedString.Key.link". Any Suggestions How can I achieve that.

let linkString = NSMutableAttributedString(string: name)
linkString.addAttribute(NSAttributedString.Key.link, value: "name:\(userID)_section:\(section)", range: NSMakeRange(0, name.count))

I am using the above code for link creations I have tried to remove long press gesture on UITextView but that did not work out

Federico Navarrete
  • 3,069
  • 5
  • 41
  • 76
iOSDev
  • 412
  • 10
  • 30
  • 1
    Maybe by playing with the values: https://developer.apple.com/documentation/uikit/views_and_controls/drag_and_drop_customization ? – Larme Aug 30 '21 at 12:18
  • Unrelated but `NSMakeRange(0, name.count)` should be `NSMakeRange(0, utf6.count)` since NSString use UTF16 and default Swift UTF8 for the count, so you might encounter issues. – Larme Aug 30 '21 at 12:19

1 Answers1

0

If I understand correctly, you don't want to display menu when link is long pressed. When UITextItemInteraction presentActions is call, we return false to disable interaction

func textView(_ textView: UITextView, shouldInteractWith URL: URL, in characterRange: NSRange, interaction: UITextItemInteraction) -> Bool {
    switch interaction {
    case .invokeDefaultAction:
        print(URL)
        return true
    case .presentActions, .preview:
        return false
    }
}
wlixcc
  • 1,132
  • 10
  • 14