0

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.

enter image description here

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)
8
  • How are you testing switching language? Commented Nov 26, 2024 at 6:44
  • Can you use SF Symbols? chevron.forward an chevron.backward will automatically adapt to the locale Commented Nov 26, 2024 at 7:15
  • @duckSern1108 Its old project. Previous developer already implemented localization and language switch between english and arabic. After switch to arabic all my layouts in RTL. problem only in icons flipping. He missed to implement this. I am Android developer, iOS I have limited experience. Commented Nov 26, 2024 at 7:22
  • @Paulw11 thanks for suggestion, its good solution. But UI/UX team gave me custom icons :( Commented Nov 26, 2024 at 7:24
  • 2
    It is better to have the user select their preferred language in the app settings in the settings app. Unfortunately trying to change the language in the app itself can be unreliable Commented Nov 26, 2024 at 7:57

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.