创建显示UIImageView:
声明var imageview:UIImageView!
在viewDidLoad()方法中初始化
self.imageview = UIImageView(frame:CGRect(x:20,y:120,width :280,height:280))
imageview.backgroundColor = UIColor.blueColor()
self.view.addSubview(imageview)
添加点击事件:
第一步:
//Enable用户交互
self.imageview.userInteractionEnabled =true
//添加手势识别
self.imageview.addGestureRecognizer(UITapGestureRecognizer(target:self,action: "touchSelect:"))
第二步:
func touchSelect(sender:UITapGestureRecognizer)->Void{
print("你点击了我")
}
原文链接:https://www.f2er.com/swift/322995.html