03/05/2018 : Since @SalmaGh have answers his owned Question.
But the solution would make your UI/UX mess up badly.
I would give a suggestion on how i would solve this issue.
This answer was refer from multiple answer who would deserve to be upvoted instead of downvote.
Reason: Adding a language switcher to your app is only going to make it more confusing
This solution is required since some of arabic language such as mention by @Afshin M. Khiabani are done in App Manually instead of Library/Framework/Device Default. this gives developer more control over their apps. however this method are not prefer.
WARNING: This will mess up Horizantal Scrollview with Subviews
But if you must force LTL view to be RTL. suggest to used IOSPercy and Jaydip answer. but please do make a flagging for checking. such as let isArabic = false
or used user default.
First enter code inside AppDelegate didFinishLaunchingWithOptions
why should we put this checking in the AppDelegate is because UIView on AppDelegate would be the superview to all view controller.
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
self.ChangeLayout()
return true
}
func ChangeLayout(){
var languageCode = ""
if let value = UserDefaults.standard.string(forKey: "Applanguage") {
languageCode = value
}else{
languageCode = ""
}
if(languageCode == "ar"){
UIView.appearance().semanticContentAttribute = .forceRightToLeft
}else{
UIView.appearance().semanticContentAttribute = .forceLeftToRight
}
}
This code will automatically Load the apps in RTL mode if Applanguage save "ar" however this will only happen once when you reopen the apps.
But you can access the function by calling the AppDelegate Function Like so:
let appDelegate: AppDelegate? = UIApplication.shared.delegate as? AppDelegate
appDelegate?.ChangeLayout()
Then Call TopMost ViewController such as LoadingScreen or something to make the Reload flow.