Kushal Hyperlink
Kushal Hyperlink

Reputation: 31

ios swift how to change RTL to LTR view when change the language?

Currently, I am working with localization on English and Arabic language. To change from RTL to LTR view I used exit(0) this will stop the app and user have to open it again. For that Apple reject my application while uploading to the app store.

I referred https://itunes.apple.com/us/app/talabat-for-ipad/id477430407?mt=8 , it will chagne view without exit the app.

Thanks in advance.

Upvotes: 2

Views: 8384

Answers (1)

Agent Smith
Agent Smith

Reputation: 2923

You can change UIView's semanticContentAttribute with appearance proxy where you are calling exit(0) and setting the rootViewController of the window again.

func switchViewControllers(isArabic arabic : Bool){

        if arabic {
            UIView.appearance().semanticContentAttribute = arabic ? .forceRightToLeft : .forceLeftToRight
            let appDelegate = UIApplication.shared.delegate as? AppDelegate
            let homeViewController = HomeViewController()
            appDelegate?.window?.rootViewController = homeViewController
         }
}

Upvotes: 7

Related Questions