Search code examples
iosswiftlocalizationuiappearance

Changing appearance right after changing app language on fly causing problem in iOS using swift


I have both options Appearance and change Language (to Arabic) in my iOS app. When you change language and try to change appearance, some UI elements restores their direction i.e RTL to LTR

I'm doing method swizzling for changing app language, Don't want to restart the app. I think this is causing the problem.

Here is how i am changing ui appearance

UIApplication.shared.windows.first?.overrideUserInterfaceStyle = theme.uiInterfaceStyle

Note: If you restart the app after changing language, and change appearance work fine.


Solution

  • I had a similar problem. Since you are messing up with the UIWindow, right after overriding appearance, it restores your previous method swizzling.

    What you need to do is to call the change language method again to the currently selected/set language.