How to set minimum and maximum hour to UIDatePicker ? At all is it possible ?
I know how to set minimum and maximum date:
[datePicker setMinimumDate: today];
This works in "TIME MODE", otherwise selected answer should work unintuitively though
// minimum time
components.hour = 0
components.minute = 0
let minTime = calendar.date(from: components)
// max time
components.hour = 23
components.minute = 59
let maxTime = calendar.date(from: components)
// selected value current time or saved time
let selectedDate = Date() // or saved time
let nowComp = calendar.dateComponents([.hour, .minute], from: selectedDate)
components.hour = nowComp.hour
components.minute = nowComp.minute
let selectedTime = calendar.date(from: components)!
play with the values and use as below
datePicker.datePickerMode = .time
datePicker.date = selectedTime
datePicker.minimumDate = minTime
datePicker.maximumDate = maxTime