简体   繁体   中英

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. This is placed outside of my 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

    }()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM