Reputation: 181
Please advice how to change all the app programatically to right to left. from iOS 9 apple set the hebrew / arbic region as left to right (mirroring).
Please advice if there is any option to change this ?
Regards Yakir.
Upvotes: 1
Views: 1004
Reputation: 896
if(OS_GREATER_THAN_OR_EQUALTO(@"9.0"))
{
if(RightToLeftLanguage)
{
[[UIView appearance] setSemanticContentAttribute:UISemanticContentAttributeForceRightToLeft];
}
else
{
[[UIView appearance] setSemanticContentAttribute:UISemanticContentAttributeForceLeftToRight];
}
}
"[[UIView appearance] setSemanticContentAttribute:UISemanticContentAttributeForceRightToLeft];" this statement enforce the view to be rendered in right to left mode without considering your app or device language. Make sure call this statement in viewDidLoad.
Upvotes: 0
Reputation: 739
In addition to the answer of Boaz - It might be better and safer to place this code in the main.m file instead of in the didFinishLaunching
method.
(don't have enough Rep. to add this as a comment the the original answer)
And... You don't need to get the array of languages/check the first language, you can simply set it to be "en":
NSUserDefaults * defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:[NSArray arrayWithObject:@"en"] forKey:@"AppleLanguages"];
[defaults synchronize];
Upvotes: 1
Reputation: 5084
Change the interface language to English. Currently it is the only way (unless apple will get convinced it was a bad idea)
Edit:
If you want your app to behave "English only" - you can force the locale in the code:
In AppDelegate
add to didFinishLaunchingWithOptions
:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSArray *languages = [[NSUserDefaults standardUserDefaults] objectForKey:@"AppleLanguages"];
if (![[languages firstObject] isEqualToString:@"en"]) {
[[NSUserDefaults standardUserDefaults] setObject:@[@"en"] forKey:@"AppleLanguages"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
}
Upvotes: 2