How to apply the Theme in iOS Native apps

佐手、 提交于 2019-12-25 05:16:11

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!