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

Swift UIImageView 构造方法

发布时间:2020-12-14 01:49:54 所属栏目:百科 来源:网络整理
导读:UIImageView有三个构造方法 init (frame: CGRect ) 我们可能发现UIImageView并没有这个构造方法,其实他是继承父类UIView的方法 //1,init(frame:CGRect) let imgV=UIImageView(frame: CGRectMake(20,50,100,100)) let img=UIImage(named: "test0.png") imgV.

UIImageView有三个构造方法


init(frame:CGRect)

我们可能发现UIImageView并没有这个构造方法,其实他是继承父类UIView的方法

//1,init(frame:CGRect)
        let imgV=UIImageView(frame: CGRectMake(20,50,100,100))
        let img=UIImage(named: "test0.png")
        imgV.image=img
        self.view .addSubview(imgV)


init(image:UIImage!)


这个比较简单直接看代码

        //2,init(image:UIImage)
        let imgV1=UIImageView(image: img)
        imgV1.frame=CGRectMake(20,200,100)
        self.view .addSubview(imgV1)

init(image:UIImage!,highlightedImage: UIImage?)


        
        //3,init(image:UIIImage!,highlightedImage:UIImage?)
        let imgV2=UIImageView(image: img,highlightedImage: UIImage(named: "test1.png"))
        imgV2.frame=CGRectMake(20,350,100)
        self.view.addSubview(imgV2)
        
        //第三个构造方法的第二参数为imageView高亮的时候会现实的图片。这里我们手动模拟一下直接设置为高亮看效果
        imgV2.highlighted=true
        
      


苹果开发群 :414319235 欢迎加入 欢迎讨论问题

(编辑:李大同)

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

    推荐文章
      热点阅读