views:

35

answers:

2

I've got an app where the background needs to be set depending on user preference. The user can change this at any time via settings tab. I've got it working by checking NSUserDefaults in viewWillAppear and setting self.view.backgroundColor. This is really clunky.

The right approach (I thought) is to set the background in the root view and for every views that gets on the stack inherit the background. So in viewDidLoad, I've got

self.view.backgroundColor = [UIColor clearColor];

I would have thought this should work. But all I get is a clear background. Any guidance is greatly appreciated.

A: 

Your first approach was right. Pushed views don't "go over" the root view--old views are pushed off the screen (and can be released if there is a memory warning). You have to set the background color in each view. If you want to avoid redundancy, you can make an abstract superclass that sets the background color.

eman
A: 

Views are layered.

So if there are views "on top of" the root view and you want to "see" the root view's background color, make sure any views on top are transparent (i.e. Opaque is off, and/or the background alpha is 0.0).

ohho