UIDatePicker 15 Minute Increments Swift

不羁的心 提交于 2020-05-14 14:50:07

问题


In swift, I'm wondering how I would use my UIDatePicker to select 15 minute increments. So instead of having hours with 60 minutes, I only want to be able to select 00 minutes, 15 minutes, 30 minutes, and 45 minutes.

Here is my current implementation

var schedulePicker: UIDatePicker = UIDatePicker()

schedulePicker.datePickerMode = UIDatePickerMode.DateAndTime
    schedulePicker.addTarget(self, action: "handleSchedulePicker:", forControlEvents: UIControlEvents.ValueChanged)
    textField9.inputView = schedulePicker

....
func handleSchedulePicker(sender: UIDatePicker) {
    var dateFormatter = NSDateFormatter()
    dateFormatter.dateFormat = "MMM/dd/yy hh:mm a"
    textField9.text = "\(dateFormatter.stringFromDate(sender.date))"
}

回答1:


Set shedulePicker.minuteInterval = 15

I found the answer here: https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIDatePicker_Class/#//apple_ref/occ/instp/UIDatePicker/minuteInterval

It's always good to take a look at documentation :)




回答2:


You can set on the attributes inspector In the "Interval"



来源:https://stackoverflow.com/questions/30245341/uidatepicker-15-minute-increments-swift

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!