I am new to Swift and I am trying to change the application views direction from LTR to RTL when the user click Arabic language button. So far I have this code below and all the text changed correctly unless the direction. The direction works only if I closed and reopened the application. Please help
@IBAction func goToLanguage(sender: AnyObject) {
let availableLanguages = Localize.availableLanguages()
actionSheet = UIAlertController(title: nil, message: "Switch Language", preferredStyle: UIAlertControllerStyle.ActionSheet)
for language in availableLanguages {
let displayName = Localize.displayNameForLanguage(language)
let langString = language as String
if(langString != "Base"){
let languageAction = UIAlertAction(title: displayName, style: .Default, handler: {
(alert: UIAlertAction!) -> Void in
Localize.setCurrentLanguage(language)
NSUserDefaults.standardUserDefaults().setObject([language], forKey: "AppleLanguages")
NSUserDefaults.standardUserDefaults().synchronize()
let delegate = UIApplication.sharedApplication().delegate as! AppDelegate
delegate.refreshEverything()
})
actionSheet.addAction(languageAction)
}
}
let cancelAction = UIAlertAction(title: "Cancel", style: UIAlertActionStyle.Cancel, handler: {
(alert: UIAlertAction) -> Void in
})
actionSheet.addAction(cancelAction)
self.presentViewController(actionSheet, animated: true, completion: nil)
}