本地化+自定义UIDatePicker的日期格式 [英] localizing + customizing the date format of a UIDatePicker
问题描述
我需要自定义和本地化 UIDatePicker
的 DateAndTime
模式的日期格式,以便它以 Arabic
显示日期数字>语言以及24小时格式的时间和阿拉伯数字.
英语中的等效行将是: 2017 11 15 17:00
我尝试了所有关于SO的解决方案,从更改语言环境到更改设备语言,但无济于事.
让我们分解一下:
- 要将日期选择器的内容显示为阿拉伯语,您需要将其设置为所需的
此外,还有以下问题:
Let's breaking it down:
- For displaying the content of the date picker to be in Arabic language you'd need to set it your desired
locale
:
The locale used by the date picker.
- For changing the format of the date picker, well... it depends on the used locale; As mentioned in the UIDatePicker - Internationalization:
Date pickers handle their own internationalization; the only thing you need to do is specify the appropriate locale. You can choose a specific locale for your date picker to appear in by setting the Locale (locale) field in Attributes Inspector. This changes the language that the date picker uses for display, but also the format of the date and time (for example, certain locales present days before month names, or prefer a 24-hour clock over a 12-hour clock)...
which means that setting the desired locale for changing the language also affects the format date of the date picker.
Roughly speaking, setting both language and format is unavailable for your case, you should choose the desired language or the desired date format.
However, applying the first point (changing the date picker locale):
datePicker.locale = Locale(identifier: "ar")
should leads to the following output:
Also, the following question:
is also related to changing the date picker format.
这篇关于本地化+自定义UIDatePicker的日期格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!