Skip to content

Instantly share code, notes, and snippets.

@laevandus

laevandus/HyperlinkLabel.swift Secret

Created Dec 17, 2020
Embed
What would you like to do?
var didTapOnURL: (URL) -> Void = { url in
if UIApplication.shared.canOpenURL(url) {
UIApplication.shared.open(url, options: [:], completionHandler: { success in
if success {
print("Opened URL \(url) successfully")
}
else {
print("Failed to open URL \(url)")
}
})
}
else {
print("Can't open the URL: \(url)")
}
}
override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
if let url = self.url(at: touches) {
didTapOnURL(url)
}
else {
super.touchesEnded(touches, with: event)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment