在 Datepicker 中,我设置了 uidatepicker 可以滚动的最小和最大时间,例如,我将 3:00PM 设置为最小时间,将 8:00PM 设置为最大时间,当我运行应用程序时,我希望 datepicker 显示最小时间而不是当前时间的设备。我在我的项目中硬编码了 UIDatepicker,并没有在 xib 文件中使用。我已经设置了最小时间,但是当我从 control.tag ==1 切换到 2 时,最小时间会发生变化,而且当我第一次打开应用程序时,日期选择器不会从最小时间开始。
更新 :
-(IBAction)notificationButtonChanged:(UIButton *)control
{
if (control.tag == 1)
{
self.selectedButton = control.tag;
[userTimePicker reloadInputViews];
[components setHour:7];;
[components setMinute:00];
NSDate *date1 = [gregorian dateFromComponents:components];
[components setHour:11];
[components setMinute:00];
NSDate *date2 = [gregorian dateFromComponents:components];
[userTimePicker setDatePickerMode:UIDatePickerModeTime];
[userTimePicker setMinimumDate:date1];
[userTimePicker setMaximumDate:date2];
}
if (control.tag == 2)
{
self.selectedButton = control.tag;
[userTimePicker reloadInputViews];
[components setHour:12];
[components setMinute:00];
NSDate *date1 = [gregorian dateFromComponents:components];
[components setHour:17];
[components setMinute:00];
NSDate *date2 = [gregorian dateFromComponents:components];
[userTimePicker setDatePickerMode:UIDatePickerModeTime];
[userTimePicker setMinimumDate:date1];
[userTimePicker setMaximumDate:date2];
}
}