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

前端 未结 11 1837
后悔当初
后悔当初 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:08

    In iOS 9 one can determine the current direction for each individual view.

    if #available(iOS 9.0, *) {
      if UIView.userInterfaceLayoutDirection(
        for: myView.semanticContentAttribute) == .rightToLeft {
    
          // The view is shown in right-to-left mode right now.
      }
    } else {
        // Use the previous technique
        if UIApplication.shared.userInterfaceLayoutDirection == .rightToLeft {
    
            // The app is in right-to-left mode
        }
    }
    

    This is the recommended way of determining the layout direction in iOS 9.

    WWDC 2015 video New UIKit Support for International User Interfaces. After minute 31:20.

提交回复
热议问题