Changing to right to left RTL programmatically

SalmaGh picture SalmaGh · Feb 2, 2016 · Viewed 24.9k times · Source

I'm working on an App which supports two languages: English and Arabic. When the user changes the language to Arabic, I need my app to make the text right-to-left (RTL).

I searched for this issue, and I found this answer about supporting RTL.

I would like to do apply the the above answer but in a programmatically way, because I need to change from LTR to RTL while the App is running.

Answer

Jaydip picture Jaydip · Feb 24, 2018

in Swift 4 try this,

//FOR RIGHT TO LEFT
 UIView.appearance().semanticContentAttribute = .forceRightToLeft

//FOR LEFT TO RIGHT
 UIView.appearance().semanticContentAttribute = .forceLeftToRight