Skip to content

Instantly share code, notes, and snippets.

@xyclos
Created January 14, 2016 22:31
Show Gist options
  • Save xyclos/5b88686090bc581fc942 to your computer and use it in GitHub Desktop.
Save xyclos/5b88686090bc581fc942 to your computer and use it in GitHub Desktop.
Add tap gesture recognizer to image view.
import UIKit
class ViewController: UIViewController {
var imageView: UIImageView?
override func viewDidLoad() {
super.viewDidLoad()
let screenSize: CGRect = UIScreen.mainScreen().bounds
let tapGestureRecognizer = UITapGestureRecognizer(target: self, action: Selector("imageTapped"))
if let image = UIImage(named: "autumn.jpg") {
imageView = UIImageView(image: image)
imageView!.frame = screenSize
imageView!.userInteractionEnabled = true
imageView!.addGestureRecognizer(tapGestureRecognizer)
view.addSubview(imageView!)
}
}
func imageTapped() {
print("image tapped")
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment