开发者

IOS How to refresh a running app when user selects a different theme (i.e. force view controllers to reload with different nib files)

If your app supports multiple UI themes by having multiple nib files for开发者_JAVA技巧 it's view controllers, then when the user changes the theme through a settings menu in the app, what are your options for causing the running app's view controllers to reload their views with a different nib file?

I'm already aware of the basics - i.e. that you can load a different nib file conditionally based on a setting stored somewhere like NSUserDefaults. But after that, at the moment the user (in the app) changes the theme setting, what are my choices for having the change take effect?

I imagine I could tell the user that the theme change will take effect the next time he starts the app, but what about in real-time? Can I force the app to reload views similar to the way it does when a low memory condition occurs?


I think you may be approaching this in the wrong way.

If you are simply changing colours and images depending on the theme I would consider creating one xib and changing the colours and images in code.

The problem with multiple xibs is you increase the amount of things you need to maintain when really the only variables are likely to be properties.

Changing properties is much simpler and you could also introduce a new class to manage themes

e.g.

// psuedo class/code
Theme *theme = [[Theme alloc] initWithStyle:ThemeWarm];

self.view.backgroundColor = theme.backgroundColor;
self.view.logo            = theme.logo;
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜