0

I have a UIListView controller that has a UIToolbar at the bottom with 3 buttons. Like so:

Storyboard setup

Now, I am trying to make my app support other languages and when I change the language of the iPhone simulator to some language that is right-to-left, the toolbar shows up like this:

enter image description here

It seems like the next day button is being switched with the previous day button. Because when I press on the left button it, changes the date forward a day. I, of course, do not want this, can anyone help me fix this issue.

Here is what I tried to so far to try and fix this issue:

I tried to change the semantic of the UIToolbar to "Force Left-to-Right" I tried doing the same for all the views in that the toolbar is in, no luck. I even tried changing the semantic programmatically like this:

toolbar.semanticContentAttribute = .forceLeftToRight 

At this point, I have no idea how to fix this issue, any help is appreciated!

3
  • The correct fix is to localise your images so that the "Next day" arrow is a left pointing arrow for right-to-left locales and a right pointing arrow for left to right locales and vice-versa for the "previous day" arrow. In a right to left locale, the left hand button would be expected to move to the next day. Forcing the semantics of the toolbar is ignoring the appropriate behaviour for the locale. Commented Feb 11, 2024 at 23:55
  • I had no idea images could be localized. Thank you! I will look into it! Commented Feb 12, 2024 at 0:06
  • Although, the images are from the system, there wasn't really an option to localize them from what I saw Commented Feb 12, 2024 at 0:07

1 Answer 1

2

Attempting to force a left to right layout is not the correct approach for dealing with a right-to-left locale.

In a right to left locale, an arrow on the right side, pointing right would be expected to go back. If you forced the button on the left to go back it would be confusing for those users.

There are two similar, but subtly different SF symbols you can use for the arrows you are showing:

arrowtriangle.left.fill and arrowtriangle.right.fill will always show the same image, regardless of locale. That is they will always point left and right.

arrowtriangle.backward.fill and arrowtriangle.forward.fill will adjust their appearance depending on the locale. In a left-to-right locale, arrowtriangle.backward.fill will point left, but in a right-to-left locale it will point right.

The toolbar is changing its layout to suit the locale - In a right to left locale it puts the first bar button item on the right.

Because you have used arrowtriangle.left.fill as the image for your first button item, you end up with an arrow pointing in the wrong direction.

Simply change the image names to use forward and backward instead of left/right and it will all work automatically.

Sign up to request clarification or add additional context in comments.

4 Comments

But I am using arrowtriangle.left.fill
I tried switching to arrowtriangle.backwards.fill and it gave me the same result!
Oh! I fixed it! I removed the "Force Left-to-Right" semantic and it worked! Thanks!
Thanks to @HangarRash for the clue regarding the different symbols available

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.