With left-to-left RTL software

I am working on an application that supports two languages: English and Arabic. When the user changes the language to Arabic, I need an application to make the text from right to left (RTL).

I searched for this problem and I found this answer about RTL support.

I would like to apply the above answer, but programmatically, because I need to change from LTR to RTL while the application is running.

+6
source share
5 answers

I changed my left-to-left RTL application using this:

self.transform = CGAffineTransformMakeScale(-1.0, 1.0) 

This flipped the view, then I flipped the objects in the view as follows:

 label.transform = CGAffineTransformMakeScale(-1.0, 1.0) textField.transform = CGAffineTransformMakeScale(-1.0, 1.0) image.transform = CGAffineTransformMakeScale(-1.0, 1.0) 

This made my RTL representations instead of changing all restrictions or rebuilding the application as RTL.

+6
source

in Swift 4 try this,

 //FOR RIGHT TO LEFT UIView.appearance().semanticContentAttribute = .forceRightToLeft //FOR LEFT TO RIGHT UIView.appearance().semanticContentAttribute = .forceLeftToRight 
+1
source

Since this is your own application, I'm going to assume that you control its user interface elements.

If so, not only can you provide NSLayoutConstraint that suit your requirements, you can also specify the alignment for representing the text and buttons: NSTextAlignment .

Since you cannot manage program settings programmatically, keep in mind that your application will no longer use natural restrictions, such as leading or trailing .

0
source

Do you mind if I ask why you need it?

I would highly recommend thinking twice before doing this, mainly because it creates a confusing user interface. Users expect their applications to follow the system language and therefore will not have any method of selecting a language within the application.

iOS makes it easy for you to make the right decision; if you use auto-layout, create your custom controls in the UIKit API and use NSLocalizedString, everything will work correctly at runtime for your users.

0
source

Use the following lines in the didFinishLaunchingWithOptions method when you want an Arabic language layout, For SWIFT

UIView.appearance (). semanticContentAttribute = .forceRightToLeft

For goal C

[Appearance of UIView] .semanticContentAttribute = UISemanticContentAttributeForceRightToLeft;

and reload the application using

 [self application:app didFinishLaunchingWithOptions:nil]; 

in another method in appDelegate. Call this method when you change the application language.

Use the opposite for the English localization of the application.

-1
source

All Articles