I am using UITextView
in Swift 3.0 and I would like to support both English and Arabic language. When I am setting Arabic text in the UITextView
, it is aligned left to right instead of right o left.
I have set the alignment to natural in storyboard but it is not working. I want to show text left to right in case of english and right to left in case if arabic text.
How can I achieve it in Swift 3.0?
you can try this code:
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
}
}