Suppose I have an AttributedString : \"Already have an account? Sign in!\". I am placing this String in UILabel. Now when a user clicks on \"Sign in!\", current viewControl
Swift 4.2 and Xcode 11 Using TextView it's much easy
func setupContactUsInTextView() {
let text = NSMutableAttributedString(string: "Contact us at email ")
text.addAttribute(NSAttributedStringKey.font,
value: UIFont.systemFont(ofSize: 17),
range: NSRange(location: 0, length: text.length))
let interactableText = NSMutableAttributedString(string: "contact@abc.com")
interactableText.addAttribute(NSAttributedStringKey.font,
value: UIFont.systemFont(ofSize: 17),
range: NSRange(location: 0, length: interactableText.length))
interactableText.addAttribute(NSAttributedStringKey.link,
value: "contact@abc.com",
range: NSRange(location: 0, length: interactableText.length))
text.append(interactableText)
contactUsTextView.attributedText = text
contactUsTextView.textAlignment = .center
contactUsTextView.isEditable = false
contactUsTextView.isSelectable = true
contactUsTextView.delegate = self
}
func textView(_ textView: UITextView, shouldInteractWith URL: URL, in characterRange: NSRange) -> Bool {
print("open website here...")
return false
}