如何在UIDatePickerModeTime中设置时间范围 [英] How to set Time Range in 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:
- 选择
日期选择器
。 - 打开
实用程序 - >属性检查器
- 块
约束
: - 选择
最短日期
并设置其值01/01/1970 16:00:00
- 选择
最大日期
并设置其值01/01/1970 19:00:00
- 设定值
日期
至01/01/1970 16:00:00
- 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
这篇关于如何在UIDatePickerModeTime中设置时间范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!