本地化+自定义UIDatePicker的日期格式 [英] localizing + customizing the date format of a UIDatePicker

查看:93
本文介绍了本地化+自定义UIDatePicker的日期格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要自定义和本地化 UIDatePicker DateAndTime 模式的日期格式,以便它以 Arabic 显示日期数字>语言以及24小时格式的时间和阿拉伯数字.

英语中的等效行将是: 2017 11 15 17:00

我尝试了所有关于SO的解决方案,从更改语言环境到更改设备语言,但无济于事.

解决方案

让我们分解一下:

  • 要将日期选择器的内容显示为阿拉伯语,您需要将其设置为所需的

    此外,还有以下问题:

    解决方案

Let's breaking it down:

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:

Show Time in 12 and 24 hour format in UIDatePicker on the basis of app settings not on device Settings

is also related to changing the date picker format.

这篇关于本地化+自定义UIDatePicker的日期格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆