Time range on date picker for specific dates iPhone

青春壹個敷衍的年華 提交于 2019-12-14 03:04:27

问题


I want to have a time range on a UIDatePicker, so I can display what times users can book a meeting. Say on May 25th, they can book between 12pm and 8 pm, if they scroll to May 26th they can book between 4pm and 8pm.

So I'm wondering how I can display this in a UIDatePicker? Users can't choose time outside of a preset I have for each day.

Any help is appreciated!


回答1:


I found this one, hope this will help you out..

Can UIDatePicker's minimumDate and maximumDate include time?

Enjoy Coding :)




回答2:


Sorry, but no. UIDatePicker can only set ranges for dates. If you want to restrict the range of the hours, you will have to subclass uidatepicker and create your own custom class. Here's a link: UIDatePicker hours interval (NSCalendarUnit?) Hope this helped!




回答3:


I would suggest using UIPickerView to make your own date picker. Every time a date is selected, you can change what times are available inside pickerView:didSelectRow:inComponent:.




回答4:


What I ended up doing was to add a target to the date picker, and check if the time of the date chosen matched the hours I preset and display an alert view if they didn't match.



来源:https://stackoverflow.com/questions/10740778/time-range-on-date-picker-for-specific-dates-iphone

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