I'm having problems with UILabels that use NSAttributedStrings
with NSParagraphStyle
when I use UISemanticContentAttributeForceRightToLeft
.
I have a demo app with just 2 labels on the UI.
They have leading and trailing constraints.
I'm making the app Right to Left in the AppDelegate with
UIView.appearance().semanticContentAttribute = .forceRightToLeft
And I'm just configuring the labels with the following code
let labelAText = "Foo"
let mutAttrString = NSMutableAttributedString(string: labelAText)
let paragraphStyle = NSMutableParagraphStyle()
paragraphStyle.alignment = .natural
paragraphStyle.baseWritingDirection = .natural
mutAttrString.setAttributes([NSAttributedStringKey.paragraphStyle: paragraphStyle.copy()], range: NSMakeRange(0, labelAText.count))
labelA.attributedText = mutAttrString
labelB.text = "Bar"
Which results in this:
[
The labelB (Bar)
is working as expected, but the labelA (Foo)
isn't. And if I just remove the NSParagraphStyle
it starts working. Mind that I'm not even changing anything on it, but just by using it it's messing up with the alignment.
Any thoughts on what might be causing this?