Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Discarding Right to left not working in iOS

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

like image 503
iosMentalist Avatar asked Oct 18 '25 02:10

iosMentalist


1 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
        }
    }
}
}
like image 58
Shahzaib Maqbool Avatar answered Oct 19 '25 16:10

Shahzaib Maqbool



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!