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, 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, 100)
self.view.addSubview(imgV2)
//第三个构造方法的第二参数为imageView高亮的时候会现实的图片。这里我们手动模拟一下直接设置为高亮看效果
imgV2.highlighted=true
苹果开发群 :414319235 欢迎加入 欢迎讨论问题