这里使用timePicker通过UIDatePickerMode.time
现在,我现在的时间是下午3:13,但是在时间选择器中,我想显示从现在开始30分钟,即下午3:43,这意味着用户可以从下午3:43开始选择时间。我应该怎么做到这一点?
这是我试过的代码
我尝试了timePicker?.minimumDate
。但它没有工作
func timePicking(){
let timePicker = ActionSheetDatePicker(title: "Time", datePickerMode: UIDatePickerMode.time, selectedDate: NSDate() as Date!, target: self, action: #selector(self.timeSelected), origin: (sender as AnyObject).superview!?.superview)
let minimumTimeRestrict: TimeInterval = 0 * 30 * 60 * 60
timePicker?.minimumDate = NSDate(timeInterval: -minimumTimeRestrict, since: NSDate() as Date) as Date!
timePicker?.show()
}
答案 0 :(得分:1)
Swift 4.0
如果您希望在UIDatePicker
后30分钟显示时间,请添加minimumDate
,如下所示。
let nextTime = Calendar.current.date(byAdding: .minute, value: 30, to: Date())
timePicker.minimumDate = nextTime