iPhone:DatePicker dd/mm/yyyy [英] iPhone:DatePicker dd/mm/yyyy
问题描述
当用户单击文本字段时,我正在使用带有弹出窗口的 DatePicker.但是,选择器先显示月份,而不是先显示日期,而且这不是英式日期书写方式.有什么方法可以将 DatePicker 中的日期格式设置为英国方式,例如 dd/mm/yyyy?我正在使用 Achtionsheet:
I am using a DatePicker with popups when a user click a textField. However, the Picker displays Month first, not date first and it isn't British way to write a date. Is there any way to set the date format in DatePicker to British way such as dd/mm/yyyy? I am using an 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]
规定的任何内容.
The UIDatePicker
, by default, uses whatever [NSLocale currentLocale]
dictates.
UIDatePicker
上的 locale
属性在 iOS 5 中已被弃用,但我相信您可以执行以下操作:
The locale
property on UIDatePicker
was deprecated in iOS 5, but I believe that you could do the following:
NSCalendar *cal = [NSCalendar currentCalendar];
cal.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_GB"];
myDatePicker.calendar = cal;
这应该有效.如果没有,请提交错误,我会修复它.:)
This should work. If it doesn't, please file a bug and I'll fix it. :)
这篇关于iPhone:DatePicker dd/mm/yyyy的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!