加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

swift UIImageView

发布时间:2020-12-14 06:43:52 所属栏目:百科 来源:网络整理
导读:创建显示UIImageView: 声明 var imageview: UIImageView ! 在viewDidLoad()方法中初始化 self . imageview = UIImageView (frame: CGRect (x: 20 ,y: 120 ,width : 280 ,height: 280 )) imageview . backgroundColor = UIColor . blueColor () self . view

创建显示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("你点击了我")

}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读