[英]CGRect is not working in closure outside of viewDidLoad
我正在嘗試使用CGRect
制作一個矩形形狀,然后在此工作后將其返回,它將允許我對其設置約束以將其放置在我想要的位置,我在此閉包內使用它,它給了我一個錯誤. 這位於我的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
}()
您可能應該使您的徽標成為惰性變量。 這樣做:
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.