change the background color of all the viewcontrollers iphone

Go To


I need to change the background color of all the UIviewcontrollers in my app simulteniousely like choosing blue make all blue and green do the same.

2012-04-04 19:04
by Ahsan Muhammad


One approach is to fire a notification once the color is changed and make all the viewcontrollers as the listner.. then you can change the color in selector called for that notification...

(If u want to avoid writing this whole procedure again and again you can create a base view controller subclassing the UIViewController and all the viewcontrollers will subclass this baseview controller... doing this you will have to define the listner function only once in the baseviewcontroller) .. hoping this helps... :)

2012-04-04 19:34
by Ankit Srivastava


Most apps view controller's are visible only one at a time. If that's true for your app, then your VCs can set their view background color before they appear.

- (void)viewWillAppear:(BOOL)animated {

    if (/* the condition that makes me supposed to have a blue background */) {

        // I was supposed to be blue already, but nobody can see me yet,
        // so everything is cool

        self.view.backgroundColor = [UIColor blueColor];
2012-04-04 19:48
by danh


You cannot set the backgroundColor for UIViewController, only for it's view property. Well, you can make this UIColor value as global and when setting it, post and observer event, which will be reach to the method in each UIViewController to set its self.view.backgroundColor to specified color.

2012-04-04 19:09
by demon9733


The best approach to this task is to refactor your common aesthetics and view logic to a base class. For instance, in most of my projects I have a class called BaseViewController. All UIViewControllers extend from this base class. In the viewDidAppear and viewDidLoad methods I complete the appropriate setup for every view in my application. Then when you (inevitably) want to change the looks of your app, the code is only in ONE place!

2012-04-04 21:04
by Sam