iOS - Change Language for UIDatePicker by locale

2019-02-21 02:18发布

问题:

I'm creating the app in "Herbrew" language. (Language of IPhone can be anything, but my app runs only in Herbrew). In iOS for UIDatePicker, we have a property "locale" which will change the language that it is displaying. But in iOS5, the property is deprecated. How can I achieve it now?

回答1:

Unfortunately, you cannot achieve this, not even with the calendar trick described by Martin Ulrich. I've struggled with the same problem myself and after a long research, I found out the bitter truth: the only way to change the localization of the UIDatePicker is to change the device's language.

If the user will have the app's language as Hebrew, everything will be alright. If not, there's nothing you can do, except maybe create your own date picker. Sorry



回答2:

You can set the calendar property of the UIDatePicker to [NSCalendar currentCalendar]