Updated 26 October 2021
Sometimes we need to make the application for both LTR as well as RTL. here is some concepts that will work for LTR, RTL but this will support for iOS 9.0 and greater.
Here are some steps to follow:
1: Select the project and set Localization language and select (use base internationalization).
2: Now you write code where the user will choose the language.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
@IBAction func `switch`(_ sender: Any) { if L102Language.currentAppleLanguage() == "en" { L102Language.setAppleLAnguageTo(lang: "ar") UIView.appearance().semanticContentAttribute = .forceRightToLeft } else { L102Language.setAppleLAnguageTo(lang: "en") UIView.appearance().semanticContentAttribute = .forceLeftToRight } let rootviewcontroller: UIWindow = ((UIApplication.shared.delegate?.window)!)! rootviewcontroller.rootViewController = self.storyboard?.instantiateViewController(withIdentifier: "rootnav") let mainwindow = (UIApplication.shared.delegate?.window!)! mainwindow.backgroundColor = UIColor(hue: 0.6477, saturation: 0.6314, brightness: 0.6077, alpha: 0.8) UIView.transition(with: mainwindow, duration: 0.55001, options: .transitionFlipFromLeft, animations: { () -> Void in }) { (finished) -> Void in } } } let APPLE_LANGUAGE_KEY = "AppleLanguages" /// L102Language class L102Language { /// get current Apple language class func currentAppleLanguage() -> String{ let userdef = UserDefaults.standard let langArray = userdef.object(forKey: APPLE_LANGUAGE_KEY) as! NSArray let current = langArray.firstObject as! String return current } /// set @lang to be the first in Applelanguages list class func setAppleLAnguageTo(lang: String) { let userdef = UserDefaults.standard userdef.set([lang,currentAppleLanguage()], forKey: APPLE_LANGUAGE_KEY) userdef.synchronize() } } |
3: Here “rootnav” is the starting view controller “storyboardId” so you can set your parent view controller storyBoardId by this way it will affect for all view controller and perform the desired operation.
If you have more details or questions, you can reply to the received confirmation email.
Back to Home
2 comments
Sorry for your late Reply , actually there is noting any issue regarding app performance it just change the view direction & nothing else so please check the other part of your code .