Skip to content

Instantly share code, notes, and snippets.

Last active Dec 28, 2019
What would you like to do?
@objc func didTapLabel(sender: UITapGestureRecognizer) {
var tappedImage = false
if let index = label.characterIndexTapped(tap: sender), let _ = label.attributedText?.attribute(NSAttributedString.Key.attachment, at: index, effectiveRange: nil) as? NSTextAttachment {
tappedImage = true
let alertTitle = tappedImage ? "Tapped Image":"Random Taps"
let alertMessage = tappedImage ? "You just tapped the image.":"You just tapped outside the image."
let alertController = UIAlertController(title: alertTitle, message: alertMessage, preferredStyle: .actionSheet)
alertController.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: nil))
present(alertController, animated: true, completion: nil)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment