Skip to content

Instantly share code, notes, and snippets.

@ycui1
Last active December 28, 2019 16:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ycui1/776a361d3494813ccab17b353e109324 to your computer and use it in GitHub Desktop.
Save ycui1/776a361d3494813ccab17b353e109324 to your computer and use it in GitHub Desktop.
@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