On LongPress on UITextView "NSAttributedString.Key.link" value is visible. How can I stop showing it to user

328 views Asked by At

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

1

There are 1 answers

0
wlixcc On

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
    }
}