Make your iOS app compatible with Right to Left languages in SwiftUI and UIKit!

Create a sample Sandbox for testing

Sample label constraints
این یک متن تست است. در این متن به بررسی عملکرد زبان های راست به چپ می‌پردازیم.
Sample Image constraints
Sample SwiftUI view with a text and an image
Preview of Sample SwiftUI view with a text and an image

Display and also Test the app in RTL

Edit the current scheme to set the launch argument
Choose Right to Left launch argument in Edit Scheme window
The sample app running in RTL mode — UIKit
The sample SwiftUI View previewing in RTL mode
Force all UIKit views to use right-to-left direction in layouts
Change all SwiftUI views to use right-to-left direction in layouts
Preview the SwiftUI view in both RTL and LTR language direction
The result of previewing the SwiftUI view in both RTL and LTR language direction

Automatic changes by iOS for Right-to-Left languages

Automatic label alignment update based on language direction
Automatic auto-layout update based on language direction

Rotate images based on language direction

Force the image to rotate in UIKit
The result of forcing the image to rotate in UIKit
Force the image to rotate in SwiftUI
The result of forcing the image to rotate in SwiftUI

Detect the language direction in the app

Detect RTL in the UIKit views
Detect RTL in the SwiftUI views
The result of detecting RTL in the SwiftUI views

Avoid the anti-pattern in the design to support Right-to-Left

An example of an incorrect pattern for the RTL compatible layout in UIKit
The result of an incorrect pattern for the RTL compatible layout in UIKit
An example of the correct pattern for the RTL compatible layout in UIKit
The result of a correct pattern for the RTL compatible layout in UIKit
An example of the correct pattern for the RTL compatible layout in SwiftUI
The result of a correct pattern for the RTL compatible layout in SwiftUI

Beyond the layout

Number pad of Persian language in iOS
Convert numbers from any language to English numbers for Integer types
An example of a Persian number and its converted English equivalent
The preview of an example of Persian number and its converted English equivalent

Conclusion

Further Reading

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store