Search code examples
iosswiftuilabelarabicarabic-support

Setting UILabel text alignment to center not working in English locale switch from Arabic in iOS


I have a UILabel which I want to align center. When I choose align center in storyboard, it works fine when the language is Arabic, which is the default. If I switch to English, it aligns to left. I tried adding in code bioLabel.textAlignment = .center, but does not work properly. How to align UILabel to center in both English and Arabic?

enter image description here enter image description here


Solution

  • If after changing language shifts your label i think you did not give proper constraints. give constraints like, greater than or equal to left and right both and horizontal in container and top from above if you want. Then user UIView's appearance for rightToLeft and leftToRight.