我正在尝试为本地化设置UITests。特别是对于阿拉伯语和任何其他从右到左(RTL)语言。

在我的情况下,我有一个swipe(direction: SwipeDirection)函数,该函数的值为SwipeDirection(.up, .down, .left, .right)。

如果我现在想删除一个单元格,那么我只需要执行cell.swipe(.left),我的UITest就会删除该单元格。由于UI翻转为RTL语言,因此必须更改为cell.swipe(.right)

我找不到任何检测当前设备语言的方法,也不是UILayoutDirection

我已经尝试像这样检查它:

let isLeftToRight = UIView.userInterfaceLayoutDirection(for: UIView().semanticContentAttribute) == .leftToRight

并且
let isLeftToRight = UIApplication.shared.userInterfaceLayoutDirection == .leftToRight

但是,无论哪种语言,它们总是返回true
还有其他方法可以检查我不知道的当前UILayoutDirection吗?

谢谢!

最佳答案

在文档中并不难找到

let locale = NSLocale.autoupdatingCurrent
let lang = locale.languageCode
let direction = NSLocale.characterDirection(forLanguage:lang!)

关于ios - 在Swift UITest中从右到左检测语言,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/43520048/

10-16 10:29