Best approach to change Xib direction programmatic

2019-05-10 16:36发布

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条回答
爷的心禁止访问
2楼-- · 2019-05-10 17:15

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.

查看更多
登录 后发表回答