Pure Layout supporting right to left

半世苍凉 提交于 2019-12-12 03:45:39

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!