3

Does iOS pure Layout support right-to-left languages? How can we implement it in the code for the arabic language without the need to go to setting and select the region and format language

Thanks

Ziad Bou Ismail
  • 187
  • 2
  • 11

2 Answers2

8

You can test in right-to-left layouts by selecting your app scheme in Xcode -> Edit Scheme... -> 'Run' -> 'Options' tab -> Application Language -> Right-to-Left pseudo language.

It is highly recommended that you use Auto Layout to specify your layouts in your views, and most of the work will be done for you if you run the app in these languages.

For more info, Supporting Right-to-Left Languages is a great starter.

wakachamo
  • 1,723
  • 1
  • 12
  • 18
  • Thanks for the answer but i prefer to change the application language inside the App. i have a language selector in the app to choose the language. if i choose Arabic which is RightToLeft the app will be transformed to RTL direction. i want to force it in the code... – Ziad Bou Ismail Oct 05 '15 at 06:30
  • This is not supported nor recommended. You should always use the system language(s), or else your user will be very confused to have to switch language inside every app. – wakachamo Oct 05 '15 at 08:49
2

Yes, you can do RTL iPhone layout support (Arabic language support)

//For Swift 4.0

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.        
        //if UserDefaults.languageCode == "ar" {
            UIView.appearance().semanticContentAttribute = .forceRightToLeft //SMP: LTR to RTL
        //}
    …
}

extension UITextField {
open override func awakeFromNib() {
        super.awakeFromNib()
        //if UserDefaults.languageCode == "ar" {
            if textAlignment == .natural {
                self.textAlignment = .right
            }
        //}
    }
}

extension UILabel {
    open override func awakeFromNib() {
        super.awakeFromNib()
        //if UserDefaults.languageCode == "ar" {
        if textAlignment == .natural {
            self.textAlignment = .right
        }
        //}
    }
}
Sandip Patel - SM
  • 3,346
  • 29
  • 27