UISemanticContentAttributeForceRightToLeft not working with adjustsFontSizeToFitWidth = YES

I'm working in an app which currently is working in English but is gonna content Arabic language obviously it will be right to left.


So I've added the following in the App Delegate:



    [[UIView appearance] setSemanticContentAttribute:UISemanticContentAttributeForceRightToLeft];


I've discovered that there are labels which are working fine but not for others, so the only difference I could find is:


self.nameLabel.adjustsFontSizeToFitWidth = YES;


If my nib file containts this option to true or it's set manually, that label will be left to right but if this option is set to false the label works fine and it becomes right to left.


Is there any reason why? or is this a bug?


Regards

Accepted Reply

Hi cepages,


A couple of things:


[[UIView appearance] setSemanticContentAttribute:UISemanticContentAttributeForceRightToLeft];

Setting the

semanticContentAttribute
on the appearance proxy is not a supported configuration. We recommend setting the
semanticContentAttribute
on individual UI elements as you see fit.


If my nib file containts this option to true or it's set manually, that label will be left to right but if this option is set to false the label works fine and it becomes right to left.

I'm not sure I'm seeing the problem on my end. When you say a label is 'left to right', do you mean the label is left-aligned? Are you able to check that the

textAlignment
property on your labels is set to
NSTextAlignmentNatural
?


Best,
w

Replies

Hi cepages,


A couple of things:


[[UIView appearance] setSemanticContentAttribute:UISemanticContentAttributeForceRightToLeft];

Setting the

semanticContentAttribute
on the appearance proxy is not a supported configuration. We recommend setting the
semanticContentAttribute
on individual UI elements as you see fit.


If my nib file containts this option to true or it's set manually, that label will be left to right but if this option is set to false the label works fine and it becomes right to left.

I'm not sure I'm seeing the problem on my end. When you say a label is 'left to right', do you mean the label is left-aligned? Are you able to check that the

textAlignment
property on your labels is set to
NSTextAlignmentNatural
?


Best,
w

Hi wakachamo


I think that was the problem, the NSTextAlignmentNatural wasn't set.


Thanks! 🙂