我在 Swift 3.0 中使用 UITextView
,我希望同时支持英语和阿拉伯语。当我在 UITextView
中设置阿拉伯文本时,它从左到右而不是从右到左对齐。
我已经在 Storyboard 中将对齐设置为自然对齐,但它不起作用。如果是英文,我想从左到右显示文本;如果是阿拉伯文本,我想从右到左显示文本。
如何在 Swift 3.0 中实现它?
最佳答案
你可以试试这个代码:
let currentDeviceLanguage = Locale.current.languageCode
if let currentDeviceLanguage = Locale.current.languageCode {
print("currentLanguage", currentDeviceLanguage)
if currentDeviceLanguage == "he" {
UIView.appearance().semanticContentAttribute = .forceRightToLeft
} else {
UIView.appearance().semanticContentAttribute = .forceLeftToRight
}
关于ios - 阿拉伯文字对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43802641/