ios - UIDatepicker设置最小分钟

标签 ios objective-c uidatepicker

我需要显示一个日期选择器,允许选择唯一的小时。目前,我的方法是将最大分钟设置为零,以便分钟选择不会启用。也许这会导致日期选择器最多选择上午 11: 00 现在我无法选择中午 12 点和下午的其他时间

这是我的代码

_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包含您要查找的唯一小时范围。

关于ios - UIDatepicker设置最小分钟,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54547800/

相关文章:

iphone - 带有页面的 UIScrollView 内的 UIDatePicker

ios - 按日期对 NSMutableArray 中的不同实体进行排序

ios - 如何从 AppDelegate 访问 TableView Controller 上声明为公共(public)的数组变量?

ios - 如何在Objective-C中创建多个锯齿状数组

iOS检查应用程序是否可以访问麦克风

Swift 2.1 - 如何更改 uidatepicker 以便它只允许时间而不是日期?

ios - fatal error : unexpectedly found nil while unwrapping an Optional value Parse sign up

objective-c - 核心数据 managedObjectContext - 它来自哪里?

objective-c - 各种 kIOPMAssertionType 的区别

ios - UITableViewCell 内的 UIDatePicker 不显示小时数