阿拉伯文字对齐

Arabic Text Alignment

我在 swift 3.0 中使用 UITextView,我想在 UITextView 中同时支持英语和阿拉伯语。当我在 UiTextView 中设置阿拉伯语文本时,它从左到右而不是从右到左对齐。

我已经在情节提要中将对齐设置为自然对齐,但它不起作用。如果是英文,我想从左到右显示文本,如果是阿拉伯文本,我想从右到左显示。

如何在 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
}

}