问题
Does iOS pure Layout support right-to-left languages? How can we implement it in the code for the arabic language without the need to go to setting and select the region and format language
Thanks
回答1:
You can test in right-to-left layouts by selecting your app scheme in Xcode -> Edit Scheme... -> 'Run' -> 'Options' tab -> Application Language -> Right-to-Left pseudo language.
It is highly recommended that you use Auto Layout to specify your layouts in your views, and most of the work will be done for you if you run the app in these languages.
For more info, Supporting Right-to-Left Languages is a great starter.
回答2:
Yes, you can do RTL iPhone layout support (Arabic language support)
//For Swift 4.0
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
//if UserDefaults.languageCode == "ar" {
UIView.appearance().semanticContentAttribute = .forceRightToLeft //SMP: LTR to RTL
//}
…
}
extension UITextField {
open override func awakeFromNib() {
super.awakeFromNib()
//if UserDefaults.languageCode == "ar" {
if textAlignment == .natural {
self.textAlignment = .right
}
//}
}
}
extension UILabel {
open override func awakeFromNib() {
super.awakeFromNib()
//if UserDefaults.languageCode == "ar" {
if textAlignment == .natural {
self.textAlignment = .right
}
//}
}
}
来源:https://stackoverflow.com/questions/32903471/pure-layout-supporting-right-to-left