UIDatePicker locale does nothing?

放肆的年华 提交于 2019-12-20 02:29:19

问题


I'm creating a UIDatePicker programmatically, and setting its locale with the following code:

datePicker.locale = [[[NSLocale alloc] initWithLocaleIdentifier:@"es_ES"] autorelease];

The datepicker still appears in English (or whatever language I've set the phone to). Anyone have any idea why this does nothing, or how to fix it?


回答1:


As answered here Can I localize a UIDatePicker?, the picker display depends on country settings, not on language settings.

In your example you are changing the language locale only.




回答2:


Try changing the locale of the UIDatePicker's calendar as well:

NSLocale *locale = [[[NSLocale alloc] initWithLocaleIdentifier:@"es_ES"] autorelease];
datePicker.locale = locale; 
datePicker.calendar = [locale objectForKey:NSLocaleCalendar]; 


来源:https://stackoverflow.com/questions/2648719/uidatepicker-locale-does-nothing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!