spoonforknife
spoonforknife

Reputation:

Can I localize a UIDatePicker?

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?

Upvotes: 9

Views: 13840

Answers (5)

fvaldivia
fvaldivia

Reputation: 474

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]]];

Upvotes: 0

Mohannad A. Hassan
Mohannad A. Hassan

Reputation: 1648

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.

Upvotes: 2

FunkyKat
FunkyKat

Reputation: 3223

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

Upvotes: 5

koffeinfrei
koffeinfrei

Reputation: 2045

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.

Upvotes: 11

David Maymudes
David Maymudes

Reputation: 5654

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?

Upvotes: 0

Related Questions