开发者

Setting background views depending on user settings

开发者 https://www.devze.com 2022-12-28 07:39 出处:网络
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 viewWillAp

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 vi开发者_运维技巧ew 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.


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.


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).

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号