Reputation: 7019
I have developed the application where I need to provide the support for two language English and Arabic. In application there is a setting screen where user can change the language from english to arabic and vice versa.
For more information please find the below screenshot for the same.
And the code which perform the localization
where I had refreshed the storyboard
to update UI.
- (void)updateLanguage {
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UIViewController *vc = [mainStoryboard instantiateViewControllerWithIdentifier:@"MainNavigationController"];
[[UIApplication sharedApplication].keyWindow setRootViewController:vc];
}
As from iOS 8
to iOS 9
, it works fine and update the UI but in iOS 10
it does not update the UI. For more information please review the below screenshot.
How I can achieve for update the UI in iOS 10
?
Below is the proper UI which need to be updated in iOS 10
.
Note : When the application came from background to foreground then it is working fine.
Upvotes: 1
Views: 2518
Reputation: 7019
I found the way how to update the layout based on language selection using 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];
}
As I had stored the current language selection in NSUserDefaults
and accordingly update the layout.
SWIFT 3.0
UIView.appearance().semanticContentAttribute = .forceLeftToRight
Upvotes: 2