开发者

How to set Time Range in UIDatePickerModeTime

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 Min开发者_StackOverflow社区time 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


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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜