简体   繁体   中英

UIDatepicker set minimum minute

I need to display a date picker which allows selecting the only hour. at present, my approach is by setting maximum minute to zero so that minute selection won't enable. Perhaps this causes the date picker to select up to 11: 00 AM Now I am not able to select 12 PM and other hours in PM

Here is my code

_PICK_timeslot.datePickerMode = UIDatePickerModeTime;
NSDateComponents *components = [[NSCalendar currentCalendar] components:NSIntegerMax fromDate:[NSDate date]];
[components setMinute:00];
NSDate *date = [[NSCalendar currentCalendar] dateFromComponents:components];
[_PICK_timeslot setMaximumDate:date];
[_PICK_timeslot addTarget:self action:@selector(listen_datePicker) forControlEvents:UIControlEventValueChanged];

UIDatePicker用于输入日期和时间值,如果只需要输入小时值,则必须设置自己的UIPickerView,其中包含要查找的唯一小时范围。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM