swift UIImageView
创建显示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("你点击了我") } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |