iosobjective-ciphonexcode

Creating Right to Left user interface for iOS


As per apple documentation "iOS doesn’t automatically mirror controls, so if you want this behaviour for an iOS app, subclass the control and override the drawing methods."

I want to mirror my whole UI when the user selects the language as Arabic or hebrew in the home screen. i was searching for tutorials and documentation for the same but nothing helps.

Please find what i have done till now: am using Xcode 6.1 and the app targets from iOS 7 to iOS 8.1. Autolayout is enabled and am not using left or right constraints. am using only leading or trailing constraints. Base internationalisation is enabled in project settings also have added the languages in localization. but when am running the app in device and set device language and region to arabic i cant get the mirrored UI. Do i have to do anything in code to get the mirrored UI? What is the best way to support RTL based UI? How to subclass control and override drawing methods?

sample screenshot of my app. enter image description here


Solution

  • I just found a easy way from Apple documentations instead of having 2 storyboards for RTL and LTR languages.

    1. First of all enable Base internationalisation in project settings
    2. Add your language - in my case i have added arabic and hebrew
    3. xCode will localize your stroy boards and you can see different storyboard strings for different languages
    4. Change the texts for your labels in the newly created strings file. In my case i changed in arabic and hebrew string files
    5. Use AutoLayout for designing the whole UI.
    6. Don't use Left or right constraints. Instead of use only leading and trailing constraints
    7. Add the below code in your main function and run the app in simulator
    NSArray* languages = [NSArray arrayWithObjects:@"ar", nil]; 
    [[NSUserDefaults standardUserDefaults] setObject:languages forKey:@"AppleLanguages"];
    

    Your app now will work for RTL language with mirrored UI without having 2 storyboards. Note : if you are not setting the autolayout constraints correctly it wont work. However because of the new screens you have to learn to use auto layout.