简体   繁体   中英

ViewController's background color is not changing in viewDidLoad()

If i assign VC's bg color as any color from iPhoneSdk in storyboard then below code works fine but if i assign VC's bg color any color from NamedColor then below code does not work

override func viewDidLoad() {
    super.viewDidLoad()

    self.view.backgroundColor = .red
}

Use viewWillAppear() for interface configuration:

override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)

    self.view.backgroundColor = .red
}

I just test it again and it works just fine to set the colour of a Viewcontroller's view in viewDidLoad . what i experience is, I had a view inside the contentView that took up most of the visible area, so very little of my customColor was visible. I had to set the background color of my subview to clear before I could see the changed background color.

Is it possible that you have a subview that completely fills your content view and hiding it's backgroundColor ?

If that's not the case, try adding a breakpoint to your viewDidLoad method to make sure it's being called.

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