Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
368 views
in Technique[技术] by (71.8m points)

iphone - UIDatePicker - Problem Localizing

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.

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.

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".

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.

Anyway, to simulate the localized DatePicker in the Simulator:

  1. Exit your app, go to Settings.
  2. Select General
  3. Select International
  4. Select the bottom option, Region Format.
  5. Change to the desired region.
  6. Relaunch your app and see the new UI Picker!

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...