use*_*067 5 iphone objective-c datepicker ios
当用户单击textField时,我正在使用带有弹出窗口的DatePicker.但是,Picker首先显示Month,而不是首先显示日期,并且不是英国人写日期的方式.有没有办法将DatePicker中的日期格式设置为英国方式,如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];
}
Run Code Online (Sandbox Code Playgroud)
Dav*_*ong 17
在UIDatePicker默认情况下,使用任何[NSLocale currentLocale]使然.
该locale属性UIDatePicker在iOS 5中已弃用,但我相信您可以执行以下操作:
NSCalendar *cal = [NSCalendar currentCalendar];
cal.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_GB"];
myDatePicker.calendar = cal;
Run Code Online (Sandbox Code Playgroud)
这应该工作.如果没有,请提交一个错误,我会修复它.:)
小智 7
UIDatePicker用于适应用户的设置.locale:可以使用该方法更改其格式,但现在已在iOS 5.0中弃用.
您可以在iPhone的设置中查看您的格式:
设置>常规>国际>区域格式
如果你想要一个特定的格式,考虑自己做一个选择器,但是对于日期选择器是非常不鼓励的.
| 归档时间: |
|
| 查看次数: |
13506 次 |
| 最近记录: |