【发布时间】:2017-10-24 17:34:09
【问题描述】:
所以,我尝试以编程方式将应用语言从 English 更改为 RTL 语言。文本已本地化,但布局仍为LTR,直到我重新启动应用程序,RTL 才生效。
有没有办法在不重启应用的情况下实现这一点?
【问题讨论】:
标签: ios localization right-to-left
所以,我尝试以编程方式将应用语言从 English 更改为 RTL 语言。文本已本地化,但布局仍为LTR,直到我重新启动应用程序,RTL 才生效。
有没有办法在不重启应用的情况下实现这一点?
【问题讨论】:
标签: ios localization right-to-left
我最终在运行时使用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];
}
}
【讨论】: