iPhone:DatePicker dd/mm/yyyy
当用户单击文本字段时,我使用带有弹出窗口的日期选择器。然而,选择器显示的是月份优先,而不是日期优先,这不是英国人写日期的方式。 有没有办法将DatePicker中的日期格式设置为英国方式,如dd/mm/yyyy? 我使用的是Achtionsheet:iPhone:DatePicker dd/mm/yyyy,iphone,objective-c,ios,datepicker,Iphone,Objective C,Ios,Datepicker,当用户单击文本字段时,我使用带有弹出窗口的日期选择器。然而,选择器显示的是月份优先,而不是日期优先,这不是英国人写日期的方式。 有没有办法将DatePicker中的日期格式设置为英国方式,如dd/mm/yyyy? 我使用的是Achtionsheet: -(IBAction)acsheet:(id)sender { actionSheet = [[UIActionSheet alloc] initWithTitle:nil
-(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];
}
英国人在用文本写月份时,可能会把月份放在第一位(或者至少可以接受)
但是为了回答您的问题,我不知道如何更改日期选择器的显示格式,但是您可以使用带有自定义委托和数据源的UIPickerView来创建自己的日期选择器。UIDatePicker是为了适应用户的设置而创建的。使用
locale:
方法更改其格式是可能的,但现在在iOS 5.0中已被弃用
您可以在iPhone的设置中查看您的格式:
设置>常规>国际>区域格式
如果你想要一个特定的格式,考虑制作自己的选择器,但是对于一个日期选择器来说是非常沮丧的。
< P> <代码> UIDatePicker <代码>,默认情况下,使用任何<代码> [NSLaLaCurrestLaLaLe] < /Cord>命令> < /P> iOS 5中不推荐使用UIDatePicker
上的locale
属性,但我相信您可以执行以下操作:
NSCalendar *cal = [NSCalendar currentCalendar];
cal.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_GB"];
myDatePicker.calendar = cal;
这应该行得通。如果不行,我会修好的。:) 第一天,日期是2011年1月20日,但写下2011年1月20日可能没问题(免责声明:我不是英国人,但我住在英国…),谢谢。是的,现在是第一天,但第一个月是可以接受的(只有当人们用美国的方式写作,比如2012年7月5日,这才让人困惑)。无论如何,谢谢你们的建议。谢谢,我在一台设备上试过,它用英国的方式播放。谢谢戴夫,但这不管用。还有人带着这个假面具吗?我在这里看到了BBog的答案,看起来非常令人沮丧: