【问题标题】:How to change the layout of an iOS app programmatically from LTR to RTL and vice versa?如何以编程方式将 iOS 应用程序的布局从 LTR 更改为 RTL,反之亦然?
【发布时间】:2017-10-24 17:34:09
【问题描述】:

所以,我尝试以编程方式将应用语言从 English 更改为 RTL 语言。文本已本地化,但布局仍为LTR,直到我重新启动应用程序,RTL 才生效。

有没有办法在不重启应用的情况下实现这一点?

【问题讨论】:

标签: ios localization right-to-left


【解决方案1】:

我最终在运行时使用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];
    }
}

【讨论】:

    猜你喜欢
    • 2012-05-19
    • 1970-01-01
    • 2012-04-11
    • 1970-01-01
    • 1970-01-01
    • 2021-12-23
    • 1970-01-01
    • 2017-12-19
    • 1970-01-01
    相关资源
    最近更新 更多