问题
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:
- Select your
Date picker
. - Open
Utilities -> Attribute inspector
- In block
Constraints
: - Select
Minimum Date
and set its value01/01/1970 16:00:00
- Select
Maximum Date
and set its value01/01/1970 19:00:00
- Set value
Date
to01/01/1970 16:00:00
来源:https://stackoverflow.com/questions/7568284/how-to-set-time-range-in-uidatepickermodetime