我有一个UIDatePicker
,它显示日期和时间UIDatePickerMode.dateAndTime
,当我在语言为阿拉伯语时显示选择器时,选择器通常会显示小时左边和右边的分钟没有问题,如下图:
但是,如果我将语言从英语更改为阿拉伯语,选择器会切换小时和分钟,如下所示:
我根据用户选择的语言将区域设置
设置为:
if CURRENT_LANGUAGE_IS_ARABIC == true{
pickerDate.locale = NSLocale.init(localeIdentifier: "ar") as Locale
}else{
pickerDate.locale = NSLocale.init(localeIdentifier: "en") as Locale
}
编辑:此外,当从阿拉伯语更改为英语时,选择器在错误的位置显示时间:
最佳答案
确保添加semanticContentAttribute
pickerDate.locale = NSLocale.init(localeIdentifier: "ar") as Locale
self.pickerDate.semanticContentAttribute = .forceRightToLeft
关于swift - 设置区域设置时 UIDatePicker 的时间位置错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50366823/