iOS iOS 10 中的阿拉伯语本地化问题
iOS Arabic localization issue in iOS 10
我开发了应用程序,我需要提供对两种语言的支持英语和阿拉伯语。在应用程序中有一个设置屏幕,用户可以在其中将语言从英语更改为阿拉伯语,反之亦然。
如需了解更多信息,请查看下面的屏幕截图。
以及执行 localization
的代码,其中我刷新了 storyboard
以更新 UI。
- (void)updateLanguage {
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UIViewController *vc = [mainStoryboard instantiateViewControllerWithIdentifier:@"MainNavigationController"];
[[UIApplication sharedApplication].keyWindow setRootViewController:vc];
}
从 iOS 8
到 iOS 9
,它工作正常并更新 UI 但在 iOS 10
中它不更新 UI。有关更多信息,请查看下面的屏幕截图。
如何在 iOS 10
中更新 UI?
下面是正确的 UI,需要在 iOS 10
中更新。
Note : When the application came from background to foreground then it
is working fine.
我找到了如何使用UISemanticContentAttribute
根据语言选择更新布局的方法。
Objective C
if(IS_OS_10_OR_LATER) {
if ([[[NSUserDefaults standardUserDefaults] valueForKey:@"Ln"] isEqualToString:@"Ar"])
[[UIView appearance] setSemanticContentAttribute:UISemanticContentAttributeForceRightToLeft];
else
[[UIView appearance] setSemanticContentAttribute:UISemanticContentAttributeForceLeftToRight];
}
因为我已将当前语言选择存储在 NSUserDefaults
中并相应地更新了布局。
SWIFT 3.0
UIView.appearance().semanticContentAttribute = .forceLeftToRight
我开发了应用程序,我需要提供对两种语言的支持英语和阿拉伯语。在应用程序中有一个设置屏幕,用户可以在其中将语言从英语更改为阿拉伯语,反之亦然。
如需了解更多信息,请查看下面的屏幕截图。
以及执行 localization
的代码,其中我刷新了 storyboard
以更新 UI。
- (void)updateLanguage {
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UIViewController *vc = [mainStoryboard instantiateViewControllerWithIdentifier:@"MainNavigationController"];
[[UIApplication sharedApplication].keyWindow setRootViewController:vc];
}
从 iOS 8
到 iOS 9
,它工作正常并更新 UI 但在 iOS 10
中它不更新 UI。有关更多信息,请查看下面的屏幕截图。
如何在 iOS 10
中更新 UI?
下面是正确的 UI,需要在 iOS 10
中更新。
Note : When the application came from background to foreground then it is working fine.
我找到了如何使用UISemanticContentAttribute
根据语言选择更新布局的方法。
Objective C
if(IS_OS_10_OR_LATER) {
if ([[[NSUserDefaults standardUserDefaults] valueForKey:@"Ln"] isEqualToString:@"Ar"])
[[UIView appearance] setSemanticContentAttribute:UISemanticContentAttributeForceRightToLeft];
else
[[UIView appearance] setSemanticContentAttribute:UISemanticContentAttributeForceLeftToRight];
}
因为我已将当前语言选择存储在 NSUserDefaults
中并相应地更新了布局。
SWIFT 3.0
UIView.appearance().semanticContentAttribute = .forceLeftToRight