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:
[![wrong label[2]](https://i.stack.imgur.com/n9Vcg.png)
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?

NSMutableParagraphStyle has a property baseWritingDirection (enum NSWritingDirection). Set it to rightToLeft
Try this
Edit:(May this help you)
languageName: The language specified in ISO language region format. Can be nil to return a default writing direction derived from the user’s defaults database.
Solution using languageName = "ar"
Here is list of languages: Codes for the Representation of Names of Languages
Note: Use
ISO 639-1code for language. Direction of label text depends upon natural direction of language.Here is result:
This Apple document will help you - Supporting Right-to-Left Languages