UIDatePicker - Problem Localizing

前端 未结 4 1095
南方客
南方客 2020-12-06 11:24

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 localiz

相关标签:
4条回答
  • 2020-12-06 11:34

    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!
    0 讨论(0)
  • 2020-12-06 11:36

    From my experience the "Today" is following the settings you have in your info.plist. For some reasons they've forgotten to adapt this.

    0 讨论(0)
  • 2020-12-06 11:55

    As of iOS 6 UIDatePicker no longer looks at the device's settings for locale information. You must may set the NSLocale manually or it will use the default locale.

    See this answer: https://stackoverflow.com/a/12975871/1128896

    A simple solution:

       datePicker.locale = [NSLocale currentLocale];
    

    Updated

    While the locale can now be set on UIDatePicker, by default it is set to 'Default' instead of any particular language. 'Default' will check the device's locale, and set itself to that. (see Dave DeLong's comment below). Therefore, most new projects shouldn't be impacted by this change.

    If you are working with older projects, migrating to iOS 6, you may find that the UIDatePickers which are created in xibs have their locale defaulted to 'English' or another language instead of 'Default'. (I've found all of my old projects, pre iOS6, followed this behavior). To fix this, simply change the locale to 'Default' in IB.

    0 讨论(0)
  • 2020-12-06 11:58

    What I am given to understand is that the UIDatePicker automatically shows in the locale the device is set as. I'm not sure how to override it, but it seems like you probably shouldn't override it.

    0 讨论(0)
提交回复
热议问题