在您的按钮操作中编写此代码
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 = UIDatePickerModeTime;
// NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
// [dateFormat setDateFormat:@"HH:mm:ss"];
NSDate *eventDate = dp.date;
NSDateFormatter *timeFormat = [[NSDateFormatter alloc] init];
[timeFormat setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"en_US"]];
[timeFormat setDateFormat:@"HH:mm"];
timeString = [timeFormat stringFromDate:eventDate];
[ dp addTarget: self action:
@selector(dateChanged:)
forControlEvents:UIControlEventValueChanged
];
[ self.view addSubview: dp ];
// txtProposeTime.font = [ UIFont fontWithName: @"Arial" size: 9.0 ];
// txtProposeTime.textColor = [ UIColor blackColor ];
txtProposeTime.text = timeString;
[dp setDatePickerMode:UIDatePickerModeTime];
[dateActionSheet addSubview:dp];
外部按钮编写此代码
-(void) dateChanged: (id)sender
{
UIDatePicker *control = (UIDatePicker *) sender;
control.datePickerMode=UIDatePickerModeDate;
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
// [dateFormat setDateFormat:@"MM/dd/yyyy HH:mm:ss a"];
NSDate *eventDate = control.date;
NSDateFormatter *timeFormat = [[NSDateFormatter alloc] init];
[timeFormat setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"en_US"]];
[timeFormat setDateFormat:@"dd/MM/yyyy"];
NSString *dateString = [timeFormat stringFromDate:eventDate];
txtMeetingDate.text=dateString;
}