iOS: Determine if device language is Right to Left (RTL)

前端 未结 11 1859
后悔当初
后悔当初 2020-12-04 23:20

Is there a way to easily determine if the language the device is set to is right to left (RTL)?

11条回答
  •  盖世英雄少女心
    2020-12-05 00:06

    Here is a swift 3 version:

    import UIKit
    
    extension UIView
    {
        /// Returns text and UI direction based on current view settings
        var userInterfaceLayoutDirection: UIUserInterfaceLayoutDirection
        {
            if #available(iOS 9.0, *) {
                return UIView.userInterfaceLayoutDirection(for: self.semanticContentAttribute)
            } else {
                return UIApplication.shared.userInterfaceLayoutDirection
            }
        }
    }
    

提交回复
热议问题