Supporting right-to-left languages in iOS / Swift

Here is the list of techniques I use to make my iOS apps compatible with right-to-left languages.

  1. By default Auto Layout will take care of the right-to-left layout when .Leading and .Trailing layout attributes are used.
  2. Right-to-left layout can be tested by changing Application Language settings to Right to Left Pseudolanguage in the scheme Run settings (Product > Scheme > Edit Schemeā€¦).
  3. semanticContentAttribute property of a UIView can be used to change the default layout technique. For example, one can force the view to remain in the left-to-right mode. Same can be done in the Storyboard by changing the Semantic property of the Attributes Inspector.
  4. In order to flip images for right-to-left users use imageFlippedForRightToLeftLayoutDirection() method of an UIImage object.
  5. And finally, here is how to check if the view is currently displayed in the left-to-right mode:
let isLeftToRight = UIView.userInterfaceLayoutDirection(
      for: view.semanticContentAttribute) == .leftToRight

Reference







Wooooow!