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?
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.
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
UIDatePicker
programmatically, it'll be initialized with [NSLocale currentLocale]
. If you're creating it in a xib, then make sure the value of the "Locale" attribute is "Default", and not "English (United States)". –
Swanson 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.
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?
To show the picker with the current language setted in the device, use this:
@property (weak, nonatomic) IBOutlet UIDatePicker *pickerView;
[_pickerView setLocale:[[NSLocale alloc] initWithLocaleIdentifier:[[NSLocale currentLocale] localeIdentifier]]];
© 2022 - 2024 — McMap. All rights reserved.