Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS - How to set storyboard/interface builder preview Right to Left?

I am Developing an app which supports two languages i.e English and Arabic. I have done mostly all tasks i.e localisation within app + handle UI LTR (english language) , RTL (Arabic language).

Now I want to see preview for a UI in RTL in storyboard. By default it is LTR.

What I have done till now:

+(void)initialize {
NSUserDefaults* defs = [NSUserDefaults standardUserDefaults];
NSArray* languages = [defs objectForKey:@"AppleLanguages"];
NSString *current = [languages objectAtIndex:0];
[self setLanguage:current];

}

+(void)setLanguage:(NSString *)l {
NSLog(@"\n\n\t ***** Hint Lang. selected by user: %@   ****\n\n", l);
NSString *path = [[ NSBundle mainBundle ] pathForResource:l ofType:@"lproj" ];
bundle = [NSBundle bundleWithPath:path];

}

+(NSString *)get:(NSString *)key alter:(NSString *)alternate {
return [bundle localizedStringForKey:key value:alternate table:nil];;

}

For handle UI LTR OR RTL. For example when user selects english language I set UI as

[UIView appearance].semanticContentAttribute = UISemanticContentAttributeForceLeftToRight; 

and when user selects Arabic language then I set UI as

[UIView appearance].semanticContentAttribute = UISemanticContentAttributeForceRightToLeft;

But I have to check every and run app iPhone UI screen whether it is fine or not for both LTR as well as RTL.

Is there any way by which we can see preview UI as RTL in storyboard (without to run in iPhone/simulator). Any suggestion will be Great!! Thanks in advance!!

like image 376
Ravi Avatar asked Nov 19 '22 14:11

Ravi


1 Answers

I found a useful way to quickly preview the RTL layout while editing a storyboard/xib, but only for one view (like a UIView parent container). This is not a good approach, but can save you some time and does not need to run the app.

While on the editor, you can select any View and in the inspector change the Semantic property to Force Right to Left. This will preview your layout in RTL for the selected view.

This is just a quick way to test a single container or control, the major drawback is that to preview the whole layout in RTL (including child views) you would need to go one by one and change this property.

like image 66
Herno Avatar answered Mar 01 '23 23:03

Herno