2017-05-24 53 views
0

因此,我嘗試以編程方式將應用程序語言從English更改爲RTL語言。該文本已本地化,但佈局仍爲LTR,直到我重新啓動RTL生效的應用程序。如何以編程方式將LTR改爲RTL,反之亦然?

有沒有辦法讓這種情況發生,而無需重新啓動應用程序?

+0

https://stackoverflow.com/a/41140436/6203030 –

回答

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

在iOS應用程序中,通過調用userInterfaceLayoutDirectionForSemanticContentAttribute:方法獲得UIView實例的佈局方向。例如:

if ([UIView userInterfaceLayoutDirectionForSemanticContentAttribute:view.semanticContentAttribute] == UIUserInterfaceLayoutDirectionRightToLeft) { 

} 

蘋果提供的方式來支持從右到左這裏的語言是鏈接: https://developer.apple.com/library/content/documentation/MacOSX/Conceptual/BPInternational/SupportingRight-To-LeftLanguages/SupportingRight-To-LeftLanguages.html

相關問題