Best approach to change Xib direction programmatically

岁酱吖の 提交于 2019-12-07 12:03:59

问题


I have an app that has a settings page in which the user can change the app's language. Eventually, the direction of the xibs will change. To explain a bit more, if the language is English for example, the direction will be LTR; However if it's Arabic, it will be RTL.

Question

What is the best approach to achieve this?

Approaches tried with issues

  • NSUserDefaults : When setting the language to "ar-SA", the direction changes successfully but only when it's called in the main class. When I do it in runtime, the app must be restarted to take effect. Even if there's a way to restart the app, it's not recommended and the app risks to be rejected
  • Multiple xibs : This approach will work eventually but I have to create two Xibs files for each UIView. If this is the only solution, can I create two UIViews in one xib file to avoid the confusion?

Any other advice?

Thanks


回答1:


I highly recommend ditching the in-app language switcher and directing your users to the system-wide language & region prefs where they can set their referred language.

Attempting to hand roll language support in your app will cause an endless amount of issues and bugs for your users, some of which you might not even be able to workaround. Both approaches you provide are already subpar and the second sounds like a maintainability nightmare.



来源:https://stackoverflow.com/questions/27743897/best-approach-to-change-xib-direction-programmatically

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