因此,我尝试以编程方式将应用程序语言从English
更改为RTL
语言。文本已本地化,但布局仍LTR
,直到我重新启动RTL
生效的应用程序。
有没有办法在不重新启动应用程序的情况下实现这一目标?
我最终使用如下所示的setSemanticContentAttribute
方法在运行时强制 RTL:
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];
}
}