如何在UIDatePickerModeTime中设置时间范围 [英] How to set Time Range in UIDatePickerModeTime

查看:291
本文介绍了如何在UIDatePickerModeTime中设置时间范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友们,我想在UIDatePickerModeTime中设置DatePicker的时间范围,因为我们有MaxDate和MinDate,无论是否可以设置用户选择的Mintime和Maxtime,

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,,

假设我希望用户只选择每天16:00到19:00之间的时间,那我该怎么办呢?

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,,

谢谢&问候
Ranjit

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

问候
Ranjit

Regards Ranjit

推荐答案

好的,我解决了你的问题(使用IB,但我认为你也可以通过编程方式完成)。

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

使用IB:


  1. 选择日期选择器

  2. 打开实用程序 - >属性检查器

  3. 约束

  4. 选择最短日期并设置其值 01/01/1970 16:00:00

  5. 选择最大日期并设置其值 01/01/1970 19:00:00

  6. 设定值日期 01/01/1970 16:00:00

  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

这篇关于如何在UIDatePickerModeTime中设置时间范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆