How do you right align a horizontal UIStackView?

UIStackViews align according to the user’s text direction, i.e. left aligned for English and other Roman script languages, or right aligned for languages such as Hebrew.

In my opinion, changing this for layout reasons may be a misuse of the text direction APIs, and a bit of a hack, but with that in mind:

You can change the direction for a particular view in interface builder, using the Semantic drop down, which has options for ‘Force Left-to-Right’ and ‘Force Right-to-Left’, which will change the direction they pop to but also the order they are shown in. So you will have to reverse the order of the elements in your stack view

Semantic selector in IB

Or you can do it in code, using the view’s semanticContentAttribute

stackView.semanticContentAttribute = .forceRightToLeft

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)