因此,我尝试以编程方式将应用语言从English
更改为RTL
语言。文本已本地化,但布局仍为LTR
,直到我重新启动RTL
生效的应用。
有没有办法在不重新启动应用的情况下实现这一目标?
答案 0 :(得分:0)
我最终使用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];
}
}
答案 1 :(得分:-1)
在iOS应用程序中,您可以通过调用userInterfaceLayoutDirectionForSemanticContentAttribute:方法获取UIView实例的布局方向。例如:
if ([UIView userInterfaceLayoutDirectionForSemanticContentAttribute:view.semanticContentAttribute] == UIUserInterfaceLayoutDirectionRightToLeft) {
}
Apple提供了支持从右到左语言的方法,这里是链接: https://developer.apple.com/library/content/documentation/MacOSX/Conceptual/BPInternational/SupportingRight-To-LeftLanguages/SupportingRight-To-LeftLanguages.html