Search code examples
swiftuikittogglebuttonuiswitchtoggleswitch

UISwitch too slow when forceRightToLeft


My app uses English and Arabic languages.
I have this in my AppDelegate:

if isArabic {
    UIView.appearance().semanticContentAttribute = .forceRightToLeft
}

When Arabic(forces elements to go right-to-left), all UI elements seem to work fine, except UISwiftch.
It works but it is too slow, it toggles, then after one or two seconds it changes its color depending on ON/OFF State. No more code for UISwitch except this:

@IBOutlet weak var mySwitch: UISwitch!

, so I don't know what causes this weird issue.


Solution

  • Fix I have found: Even if whole app is forced right-to-left on Arabic, I force left-to-right my UISwitch. You can do it in viewDidLoad

    mySwitch.semanticContentAttribute = .forceLeftToRight
    

    On is still On, Off is still Off, everything works, the UISwitch is on the left side of the screen because the whole screen is forced to left when Arabic, that is also fine. The only difference now is that the On state is active when you swipe toggle left(like in English), not right. But thats almost insensibly and none notices the "hack" :)