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.
- By default Auto Layout will take care of the right-to-left layout when
.Leading
and.Trailing
layout attributes are used. - 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ā¦).
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.- In order to flip images for right-to-left users use
imageFlippedForRightToLeftLayoutDirection()
method of anUIImage
object. - 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
-
New UIKit Support for International User Interfaces Video: WWDC 2015 video.
-
About Internationalization and Localization: iOS Developer Library.
Posted by Evgenii