UIDatePicker - 问题定位 [英] UIDatePicker - Problem Localizing

查看:26
本文介绍了UIDatePicker - 问题定位的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的应用程序中创建了一个 UIDatePicker 并且我还支持多种语言.我的 UIDatePicker 是在 Interface Builder 中创建的,我已经创建了一个单独的本地化 XIB,因此我可以自定义我的 UIDatePicker.

I've created a UIDatePicker in my app and I also have support for several languages. My UIDatePicker is created in Interface Builder, and I have created a seperate localization XIB so I can customize my UIDatePicker.

在 IB 中设置Locale"选项似乎没有任何作用.尝试使用 Locale 和 NSCalender 以编程方式更改我的 DatePicker 也不会通过以下代码执行任何操作:

Setting the "Locale" option in IB appears to do nothing. Attempting to change my DatePicker programatically with Locale and NSCalender also do nothing via the following code:

NSLocale * locale = [[NSLocale alloc] initWithLocaleIdentifier:@"es_ES"];
datePicker.locale = locale;
datePicker.calender = [locale objectForKey:NSLocaleCalender];

这会产生一个英文选择器.

This results in an english picker.

不过,这确实是一件很奇怪的事情.今天"这个词被翻译了.如所附屏幕截图所示.(好吧,我不允许发布图片.但是想象一个日期和时间选择器,其中包含英文May"和Today"写成Ajourd'hui".

Here's the really weird thing though. The word for "Today" is translated. As seen in the attached screenshot. (OK I'm not allowed to post images. But imagine a Date & Time picker with "May" in English and "Today" written "Ajourd'hui".

根据我所阅读的内容,以编程方式添加 UIDatePicker 似乎没有多大帮助.

Based on what I've read, adding the UIDatePicker programatically doesn't seem to help much.

推荐答案

经过进一步调查,这其实不是iPhone的语言设置处理的.UIDatePicker 根据区域格式"设置而不是语言自动本地化.这很奇怪,因为日期是本地化的,所以你会认为选择器的本地化将与 iDevice 的语言相关联,而不是区域格式.

After further investigation, this is actually not handled by the language setting of the iPhone. The UIDatePicker is automatically localized based on the "Region Format" setting and not the language. This is odd because the dates are localized, so you would think the localization of the picker would be linked to the iDevice's language not the Region Format.

无论如何,在模拟器中模拟本地化的DatePicker:

Anyway, to simulate the localized DatePicker in the Simulator:

  1. 退出您的应用,转到设置".
  2. 选择通用
  3. 选择国际
  4. 选择底部的选项,区域格式.
  5. 更改为所需的区域.
  6. 重新启动您的应用并查看新的 UI 选择器!

这篇关于UIDatePicker - 问题定位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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