Home > OS >  Shifting button image to right in arabic language without transforming the string
Shifting button image to right in arabic language without transforming the string

Time:12-08

I have a UIButton with a string and an image on it. When I open app in arabic, button was still placed on left and string on right, however the string was correctly displayed in arabic.

To move the button to right, I applied transform on the button which moved image on right and string on left which I what I wanted, however it also transformed the string. So the string looks incorrect in arabic. How do I fix it or how do I prevent the string itself from transforming?

Code:

if isRightToLeftLanguage() {
   DispatchQueue.main.async {
      self.customButton.transform = CGAffineTransform(scaleX: -1.0, y: 1.0)
   }
}

Before applying transform:

enter image description here

After applying transform:

enter image description here

CodePudding user response:

You should be setting the semanticContentAttribute on a view to ask it to draw in rightToLeft. Obviously more to do here with delivering the right attribute but this should get you going.

self.customButton.semanticContentAttribute = .forceRightToLeft

This doesn't cascade down the view stack though, as there are some views that shouldn't be reversed such as playback controls etc.

CodePudding user response:

you can use semanticContentAttribute property of button like this:-

button.semanticContentAttribute = .forceRightToLeft

according to you code it should be

if isRightToLeftLanguage() {
  DispatchQueue.main.async {
     self.customButton.semanticContentAttribute = .forceRightToLeft
  }
}
  • Related