I am working on an English / Arabic app that has localization. In one textfield I have set textAlignment
property as right
. But the content, numeric, displayed at right side.
I double checked it by debugging textAlignment
property value and it indeed is right
.
I have set alignment property programatically, as it will be changing as per language selection (i.e. on button tap). Then I set value in it and is being displayed as right aligned.
The thing is when I select the text field, suddenly the content moves to right side and displays as aligned right.
I change the layout to RTL and LTL programmatically with the following line:
UIView.appearance().semanticContentAttribute = .forceRightToLeft
I can't find a solution.
Try this approach
if isLangEn
{
self.textF.textAlignment = NSTextAlignment.left
self.parentViewOfTextF.semanticContentAttribute = UISemanticContentAttribute.forceLeftToRight
}
else
{
self.textF.textAlignment = NSTextAlignment.right
self.parentViewOfTextF.semanticContentAttribute = UISemanticContentAttribute.forceRightToLeft
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With