Discarding Right to left not working in iOS

Viewed 1278

My app supports right to left direction but i want to discard the phone language and just change direction depending on the user preference.

On a right to left phone, I forced the left to right using

 UIView.appearance().semanticContentAttribute = .forceLeftToRight

it fixed most things but not everything.

Check the text fields placeholder alignment; some labels were aligned right! Anyone has a solution how to fix this?

enter image description here

2 Answers

try this one it will change direction of your textfield's text from left to right

 extension UITextField {
  open override func awakeFromNib() {
    super.awakeFromNib()
    if UserDefaults.languageCode == "ar" {
        if textAlignment == .natural {
            self.textAlignment = .right
        }
    }
}
}

I don't know it will work for all the UITextField or not but You can try this but with single UITextField it should work

    UITextField.appearance().makeTextWritingDirectionLeftToRight(nil)
Related