iPhone:DatePicker dd / mm / yyyy

当用户单击文本字段时,我正在使用popup式DatePicker。 但是,Picker首先显示月份,而不是首先显示date,而不是英国写date的方式。 有没有办法将DatePicker中的date格式设置为英文方式,如dd / mm / yyyy? 我正在使用Achtionsheet:

-(IBAction)acsheet:(id)sender { actionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:nil cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil]; [actionSheet setActionSheetStyle:UIActionSheetStyleBlackTranslucent]; //CGRect pickerFrame = CGRectMake(0, 45, 0, 0); pickerView1 = [[UIDatePicker alloc] init]; pickerView1.datePickerMode = UIDatePickerModeDate; [actionSheet addSubview:pickerView1]; UISegmentedControl *closeButton = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObject:@"Close"]]; closeButton.momentary = YES; closeButton.frame = CGRectMake(260, 7.0f, 50.0f, 30.0f); closeButton.segmentedControlStyle = UISegmentedControlStyleBar; closeButton.tintColor = [UIColor blackColor]; [closeButton addTarget:self action:@selector(dismissActionSheet:) forControlEvents:UIControlEventValueChanged]; [actionSheet addSubview:closeButton]; [actionSheet showInView:[[UIApplication sharedApplication] keyWindow]]; [actionSheet setBounds:CGRectMake(0, 0, 320, 485)]; [pickerView1 addTarget:self action:@selector(updateLabel:) forControlEvents:UIControlEventValueChanged]; UIBarButtonItem *spacer = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil]; UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(dismissDatePicker:)] ; UIToolbar *toolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, self.view.bounds.size.height, 320, 44)]; toolBar.tag = 11; toolBar.barStyle = UIBarStyleBlackTranslucent; [toolBar setItems:[NSArray arrayWithObjects:spacer, doneButton, nil]]; [self.view addSubview:toolBar]; } 

UIDatePicker默认使用任何[NSLocale currentLocale]

UIDatePicker上的locale属性在iOS 5中已被弃用,但我相信您可以执行以下操作:

 NSCalendar *cal = [NSCalendar currentCalendar]; cal.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_GB"]; myDatePicker.calendar = cal; 

应该工作。 如果没有,请提交一个错误 ,我会修复它。 🙂

使UIDatePicker适应用户的设置。 使用locale:方法更改它的格式是可能的,但现在在iOS 5.0中已被弃用。

您可以在iPhone的设置中查看您的格式:

设置>常规>国际>区域格式

如果你想要一个特定的格式,可以考虑制作自己的select器,但是对于dateselect器来说,这是非常不鼓励的。

当用文字写月份时,英国人可能会把月份放在首位(或者至less可以接受)。

但是,要回答你的问题,我不知道更改dateselect器的显示格式的方式,但是你可以让你自己使用带有自定义委托和数据源的UIPickerView。