I have a paragraph which is a textView. I want to put hyperlinks inside some of the words in the paragraph.
var attributedString = NSMutableAttributedString(string: text)
attributedString.addAttribute(NSLinkAttributeName, value: hyperlink, range: range)
var linkAttributes = [NSForegroundColorAttributeName: UIColor.blueColor(),
NSUnderlineStyleAttributeName: 1
]
textView!.linkTextAttributes = linkAttributes
textView!.attributedText = attributedString
textView!.delegate = self
UITextViewDelegate
func textView(textView: UITextView, shouldInteractWithURL URL: NSURL, inRange characterRange: NSRange) -> Bool {
if UIApplication.sharedApplication().canOpenURL(URL) {
return true
} else {
CozyStyles.alert(title: "Sorry", message: (URL.scheme!).capitalizeFirst + " is not installed", action: "OK")
return false
}
}
This approach works but it doesn't work good enough. When simple taped it doesn't recognise the textView tap. The link must be long pressed to make it work which isn't user friendly.
Is there a work around for this?
- This solution also doesn't work since I have another tap gesture.