このコードを日付ピッカーに使用します
- (IBAction)dobbtn:(id)sender {
UIActionSheet *dateActionSheet = [[UIActionSheet alloc] initWithTitle:@"" delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:@"Done", nil];
[dateActionSheet setActionSheetStyle:UIActionSheetStyleBlackTranslucent];
[dateActionSheet showInView:self.view];
[dateActionSheet setFrame:CGRectMake(0, 200, 320, 383)];
UIDatePicker *dp = [[UIDatePicker alloc] initWithFrame:CGRectMake(0, 80, 100, 116)];
dp.datePickerMode = UIDatePickerModeDate;
[ dp addTarget: self action:
@selector(dateChanged:)
forControlEvents:UIControlEventValueChanged
];
[ self.view addSubview: dp ];
txtDob.font = [ UIFont fontWithName: @"Arial" size: 22.0 ];
txtDob.textColor = [ UIColor blueColor ];
txtDob.text = [ dp.date description ];
[dp setDatePickerMode:UIDatePickerModeDate];
[dateActionSheet addSubview:dp];
}
-(void) dateChanged: (id)sender
{
UIDatePicker *control = (UIDatePicker *) sender;
NSDate *selectedDate = control.date;
txtDob.text = [ selectedDate description ];
}