IOS - How do I customize storyboard / UI preview? From right to left?

I am developing an application that supports two languages ​​like English and Arabic. I have done basically all the tasks, i.e. localization in the application interface + handle UI LTR (English), RTL (Arabic).

Now I want to preview the UI in RTL in the storyboard. By default, this is LTR.

What I have done so far:

+(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 UI LTR OR RTL processing. For example, when the user selects English, I set the UI as

[UIView appearance].semanticContentAttribute = UISemanticContentAttributeForceLeftToRight; 

      

and when the user selects Arabic, I set the UI as

[UIView appearance].semanticContentAttribute = UISemanticContentAttributeForceRightToLeft;

      

But I have to check each one and launch the iPhone iPhone application screen whether it is good or not for both LTR and RTL.

Is there a way that we can see the UI preview as RTL in storyboard (without launching in iPhone / simulator). Any suggestion would be great !! Thanks in advance!

+5


source to share


1 answer


I found a useful way to quickly preview an RTL layout while editing a storyboard / XIB, but only for one view (like the parent container UIView

). This is not a good approach, but it can save you time and does not require you to launch the application.

While in the editor, you can select any View and change the property Semantic

to Force Right to Left

. This will preview your layout in RTL for the selected view.



It's just a quick way to test a single container or control, the main drawback of which is that to preview the entire layout in RTL (including child views), you will need to go one at a time and change this property.

0


source







All Articles