问题
I am creating a native application in which I want to implement the theme setting. I have one setting tab where the user can choose any theme.
But when the user select any theme how do I change all the UI, depending on the theme.
1- I have to restart the app from the beginning. When doing this should I use to push user to MainController? And in all the controllers in viewdidLoad I change the theme.
2- Or any other method I have to use please suggest the correct way.
回答1:
Answer of your question -
1- I have to restart the app from beginning for doing this should i use to push user to MainController. and in all the controllers in viewdidLoad i change the theme.
No. You won't need to do that, as you only have to change look and feel of the app.
2- Or any other method i have to USe Please suggest me what is the correct way.
In Controllers of your app try setting color of elements in viewWillAppear
, and all these colours are fetched from NSUserDefaults
or any other place from where you want.
When user change theme, just change the color which is stored in NSUserDefaults
or any other place, and reload only that controller with the help of utility methods. Rest view controller will automatically gets changes when they will be loaded.
Utility Class will take the responsibility to change the color of UI Element, might be you need to create 2 or 3 utility methods for this purpose.
Hope it clear some doubts.
回答2:
If you want to re-theme your app depending on what the user selects, I recommend a dynamic styling library like http://nativecss.com/
It let's you retheme your app whilst the app is running, which sounds like what you are after!
来源:https://stackoverflow.com/questions/10632372/how-to-apply-the-theme-in-ios-native-apps