How to set Time Range in UIDatePickerModeTime

天涯浪子 提交于 2020-01-15 05:06:07

问题


Hello friends I am trying to set the Time Range Of the DatePicker in UIDatePickerModeTime,as we have MaxDate and MinDate,whether its possible to set Mintime and Maxtime selected by user,,

Suppose I want the user to select the time between 16:00 to 19:00 only for each day then how can I do it,,

Thanks&Regards Ranjit

Hello friends I tried the below code to set the start time range and its working fine...

NSDate *todaysDate =[NSDate date];

NSDateComponents *comps = [gregorian components:NSYearCalendarUnit | NSMonthCalendarUnit |  NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit |NSSecondCalendarUnit fromDate:todaysDate];


[comps setHour:16];
[comps setMinute:00];
[comps setSecond:00];

 NSDate *startDate = [gregorian dateFromComponents:comps];

 NSDateComponents *startcomps = [[NSDateComponents alloc] init];
[startcomps setDay:startDay-weekday];


 self.minDate = [gregorian dateByAddingComponents:startcomps toDate:startDate   options:0];

but when I apply the same code to set the end time range its not working....can any body please help me out in this matter

Regards Ranjit


回答1:


Ok, I solved your problem (using IB, but I think you could do that programmatically too).

Using IB:

  1. Select your Date picker.
  2. Open Utilities -> Attribute inspector
  3. In block Constraints :
  4. Select Minimum Date and set its value 01/01/1970 16:00:00
  5. Select Maximum Date and set its value 01/01/1970 19:00:00
  6. Set value Date to 01/01/1970 16:00:00


来源:https://stackoverflow.com/questions/7568284/how-to-set-time-range-in-uidatepickermodetime

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