开发者

Xcode - Showing month names in portuguese when using UIDatePicker

I am using the UIDatePicker and I'd like to show month names in Brazilian Portuguese. I've already tried to use the timeZone property, no success though.

Here is my code:

UIDatePicker *pv = [[UIDatePicker alloc] initWithFrame:CGRectMake(0,0,320,216)];
pv.datePickerMode = UIDatePickerModeDate;
pv.timeZone = [NSTimeZone timeZoneWithName:@"America/Sao_Paulo"];

Does anybody would help m开发者_开发问答e?


Set the locale property on the picker to the locale you want, like this:

pv.locale = [[[NSLocale alloc] initWithLocaleIdentifier:@"pt_BR"] autorelease];

It should configure itself correctly. You may need to check [NSLocale availableLocaleIdentifiers] to determine if the locale you want is available/installed.


Clarification needed. Do you only want to set the date picker to Portuguese, and keep the rest of the app in the user's default language?

Normally the datepicker changes language with the user following the settings under settings/general/international. The datepicker will automatically adjust to the user's desired language, so you don't have to localize it directly.


You don't have to do anything. As soon as the iPhone is set to the proper locale, the UIDatePicker will show the proper values for you. That's why locale related methods and properties are deprecated. It relies on system configuration.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜