Can I localize a UIDatePicker?

2019-01-07 00:03发布

问题:

I'm trying to localize a UIDatePicker. Apple's docs say that it should autodetect the current locale, yet the language stays the same, no matter what language I select. What do I have to do?

回答1:

The locale property (and all other country specific format properties for that matter) defaults to the value returned by currentLocale, which in turns depends on the iphone's country settings, not the language settings. You need to set the appropriate country in the iphone general settings.



回答2:

NSLocale in UIDatePicker is back since iOS 6. Phone settings in iOS 6 are ignored and used en_US locale by default, so you must set locale in code



回答3:

From my experience, in iOS5 UIDatePicker seems to ignore the set locale and use the locale provided from the general settings. But it should work fine in iOS6.



回答4:

the UIDatePicker has a locale property; if you don't set it it should default to the user's preferred locale. When you say "no matter what language I select" what do you mean--are you trying to change the locale programmatically, or are you changing the device's default locale using the Settings page?