//创建UIDatePicker (高度不能修改)
UIDatePicker *datePicker =[[UIDatePicker alloc]initWithFrame:CGRectMake(0, 0, 200, 800)];
//设置默认显示时间
datePicker.date =[NSDate dateWithTimeInterval:-24*60*60 sinceDate:[NSDate date]];
//设置最小日期
datePicker.minimumDate =[NSDate dateWithTimeInterval: -24*60*60*3 sinceDate:[NSDate date]];
//设置最大日期
datePicker.maximumDate =[NSDate dateWithTimeInterval:24*60*60*3 sinceDate:[NSDate date]];
// UIDatePicker 基于UIControl
[datePicker addTarget:self action:@selector(dateAct:) forControlEvents:UIControlEventValueChanged];
//日期
datePicker.datePickerMode =UIDatePickerModeDate;
//倒计时
datePicker.datePickerMode =UIDatePickerModeCountDownTimer;
//时间
datePicker.datePickerMode =UIDatePickerModeTime;
//默认时间和日期
datePicker.datePickerMode =UIDatePickerModeDateAndTime;
[self.view addSubview:datePicker];
}
//valueChanged时 会调用该方法
- (void)dateAct:(UIDatePicker *)picker{
NSLog(@"%@",picker.date);
}