直接复制到你要点击的地方
UIDatePicker *datePicker = [[UIDatePicker alloc] init];
datePicker.datePickerMode = UIDatePickerModeTime;
datePicker.frame = CGRectMake(0, 40,272,90);
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"设置\n\n" message:nil preferredStyle:UIAlertControllerStyleAlert];
[alert.view addSubview:datePicker];
UIAlertAction *ok = [UIAlertAction actionWithTitle:@"不取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
NSDateFormatter* dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"HH:mm"];//设定时间格式
NSString *dateString = [dateFormat stringFromDate:datePicker.date];
int hh = [[dateString substringToIndex:2]intValue];
int mm = [[dateString substringFromIndex:3]intValue];
[self settingWithHour:hh WithMin:mm];
//求出当天的时间字符串
NSLog(@"%d,%d",hh,mm);
}];
UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
}];
[alert addAction:ok];//添加按钮
[alert addAction:cancel];//添加按钮
//以modal的形式
[self presentViewController:alert animated:YES completion:^{ }];