[英]CGRect is not working in closure outside of viewDidLoad
I am trying to use CGRect
to make a rectangle shape and then later return it once this works it will allow me to set constraints on it to place it where I want, I am using it inside of this closure and it is giving me an error.我正在尝试使用
CGRect
制作一个矩形形状,然后在此工作后将其返回,它将允许我对其设置约束以将其放置在我想要的位置,我在此闭包内使用它,它给了我一个错误. This is placed outside of my viewDidLoad
这位于我的
viewDidLoad
之外
let logo : UIImageView = {
let myLogo = UIImageView(frame: CGRect(x: 0, y: 0, width: self.view.frame.height*(77/812)*2.078, height: self.view.frame.height*(77/812)))
myLogo.image = #imageLiteral(resourceName: "ftrLogo")
return myLogo
}()
You should probably make your logo a lazy var.您可能应该使您的徽标成为惰性变量。 Do like this:
这样做:
lazy var logo : UIImageView = {
let myLogo = UIImageView(frame: CGRect(x: 0, y: 0, width: self.view.frame.height*(77/812)*2.078, height: self.view.frame.height*(77/812)))
myLogo.image = #imageLiteral(resourceName: "ftrLogo")
return myLogo
}()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.