开发者

Create a range of time in UiDatePicker

I have a problem with UiDatePicker. I want to create a UiDatePicker in UIDatePickerModeDateAndTime mode. My picker 开发者_如何转开发must have a range of hour but it haven't a range of day.

For example: the user can select always date form the picker, but can select the hour only in range 8.00 - 19.00.

Can you help me with a sample code?

Thanks


As you can easily see from the documentation, that's not possible with UIDatePicker. You would have to write you own date picker (by using UIPickerView).


UIDatePicker does not support this. It does have minimumDate and maximumDate properties, but these do not give you the granularity to say "any day between 8am and 7pm".

What you could do instead is use 2 UIDatePickers. The first one would be in UIDatePickerModeDate mode, and the second in UIDatePickerModeTime mode. Use the first one to choose a day, and the second one to choose a time. Once the user has chosen both, you could convert the 2 NSDates into NSDateComponents (using the [NSCalendar currentCalendar]), and take the -hour, -minute, and -second from the second one, give it to the first, and then transform the first back into an NSDate. (So basically combine the date information from the first NSDate with the time information from the second NSDate).

You should also file an enhancement request asking for this capability natively.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜