import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
let img = UIImageView(frame: CGRect(x: 50, y: 100, width: 100, height: 80))
img.image = UIImage(named: "180-0")
//设置允许交互
img.isUserInteractionEnabled = true
let tap1 = UITapGestureRecognizer(target: self, action: #selector(tapClick))
img.addGestureRecognizer(tap1)
self.view.addSubview(img)
}
func tapClick()
{
print("点击了图片")
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
网友评论