Reputation: 18356
In my iOS project I have two languages, English and Arabic.
Problem: For Arabic it will switch to RTL, but back icon we should use different icon for RTL.
From the image, I changed direction from Fixed to Both. And I added the separate icons for RTL. Problem is it always takes the LTR icons, I am expecting to pick RTL icons automatically.
Question:
How to load the different images for RTL without writing any condition in ViewController?
Because I have 100+ ViewControllers, so writing if condition in each controller to change the icon is not a best solution.
In Android we can use drawable-ar for separate RTL icons, I need similar solution in iOS.
Update:
My language switch code,
func switchLanguageAndReloadUI(to direction: UISemanticContentAttribute) {
// Update the layout direction
UIView.appearance().semanticContentAttribute = direction
// Reinitialize the root view controller
let storyboard = UIStoryboard(name: "Main", bundle: nil)
if let rootVC = storyboard.instantiateInitialViewController() {
let window = UIApplication.shared.windows.first
window?.rootViewController = rootVC
window?.makeKeyAndVisible()
// Animate the transition to prevent a black screen
UIView.transition(with: window!, duration: 0.5, options: .transitionCrossDissolve, animations: {}, completion: nil)
}
}
//for arabic
self.switchLanguageAndReloadUI(to: .forceRightToLeft)
//for english
self.switchLanguageAndReloadUI(to: .forceLeftToRight)
Upvotes: 0
Views: 51