So, I tried changing the app language programmatically from English
to an RTL
language. The text is localized but the layout is still LTR
until I restart the app that RTL
takes effect.
Is there a way to make this happen without restarting the app?
I ended up forcing RTL in runtime using the setSemanticContentAttribute
method like bellow:
if ([NSLocale characterDirectionForLanguage:languageCode] == NSLocaleLanguageDirectionRightToLeft) {
if ([[[UIView alloc] init] respondsToSelector:@selector(setSemanticContentAttribute:)]) {
[[UIView appearance] setSemanticContentAttribute:
UISemanticContentAttributeForceRightToLeft];
}
}
else {
if ([[[UIView alloc] init] respondsToSelector:@selector(setSemanticContentAttribute:)]) {
[[UIView appearance] setSemanticContentAttribute:UISemanticContentAttributeForceLeftToRight];
}
}