Change UIWindow backgroundColor from UIViewController?

2.9k views Asked by At

I have a UIViewController embedded in a UINavigationController. Inside my UIViewController I want to change the background color of the main UIWindow:

let appDelegate  = UIApplication.sharedApplication().delegate as! AppDelegate
appDelegate.window!.backgroundColor = UIColor.blueColor()

The previous code work fine on iOS8 but in iOS7 there is no change in the background color of the UIWindow when it is embedded in a UINavigationController.

How can I change the background color of the UIWindow inside my UIViewController in iOS7?

2

There are 2 answers

0
Aisultan Askarov On

If you are using a lot of popUp views and want to change background color of all the views at once just put this code in viewDidLoad of the root view. You can also modify it to change background color of a certain views.

let wins : [UIWindow] = UIApplication.shared.windows
        for win in wins {
        win.backgroundColor = UIColor.black
        }
0
Ah Pov On

Try this

    let win:UIWindow = UIApplication.sharedApplication().delegate!.window!!
    win.backgroundColor = UIColor.whiteColor()