Reputation: 23
To support the Right To Left on my app, I'm using this instructions:
[[UIView appearance] setSemanticContentAttribute:UISemanticContentAttributeForceRightToLeft];
[[UIStackView appearance] setSemanticContentAttribute:UISemanticContentAttributeForceRightToLeft];
[UITextView appearance].textAlignment = NSTextAlignmentRight;
But I have a lot of problems: -I don't understand how to refresh the UI if I need to apply the new alignment in the current view. -In a collection view the alignment doesn't change even if I use:
[[UICollectionView appearance] setSemanticContentAttribute:UISemanticContentAttributeForceRightToLeft];
so I decided to use:
self.sectionsCollectionView.transform = CGAffineTransformMakeScale(-1, 1);
and:
cell.transform = CGAffineTransformMakeScale(-1, 1);
It works, but if I push another view and after I pop to the view with the collection view, it's again aligned to the left until I tap into the section header, after the tap it goes to the right.
Upvotes: 1
Views: 490
Reputation: 9642
As per Apple's documentation,
By default, text alignment in iOS is natural; in OS X, it’s left. Using natural text alignment aligns text on the left in a left-to-right language, and automatically mirrors the alignment for right-to-left languages. For example, if you set the alignment of an
NSMutableParagraphStyle
object using the setAlignment: method, passNSNaturalTextAlignment
as the parameter.
[[(NSMutableParagraphStyle *)paraStyle setAlignment:NSNaturalTextAlignment];
However, if you want to align a control to the right in a left-to-right language (and to the left in a right-to-left language), get the layout direction, as described in Getting the Layout Direction, and set the alignment to
NSLeftTextAlignment
for a right-to-left language.
For more details, please refer Supporting Right-to-Left Languages
Upvotes: 2