如何在UIDatePickerView中隐藏未来或过去的日期 [英] How to hide future or past dates in UIDatePickerView

查看:296
本文介绍了如何在UIDatePickerView中隐藏未来或过去的日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想设计一个用于设置出生日期的UI.为此,我选择UIDatePickerView.现在,我想将日期限制在1990年1月1日到当前日期之间.它不应显示将来的日期和过去的日期.目前,我正在使用以下代码:

NSDateComponents *components=[[NSDateComponents alloc] init];

[components setYear:1900];

pickerView.datePicker.minimumDate = [[NSCalendar currentCalendar] dateFromComponents:components];
pickerView.datePicker.maximumDate=[NSDate date]

它限制了日期,但允许用户滚动到将来的日期和过去的日期.如何隐藏或避免它们?

我可以在iPad上的通讯录应用中看到该功能.要查看联系人->按顶部的"+"符号,然后按添加生日按钮.

解决方案

它滚动但显示为灰色,但无法选择,无法停止滚动

要禁用过去的日期:

 pickerView.datePicker.minimumDate=[NSDate date];

要禁用将来的日期:

pickerView.datePicker.maximumDate=[NSDate date];

如果您的应用程序需要此强制性功能,则需要尝试一些第三方应用程序,例如

I want to design a UI for setting date of birth. For that I am choosing UIDatePickerView. Now I want to restrict the dates to between 01-01-1990 and current date. It should not show future dates and past dates. Currently I am using the following code:

NSDateComponents *components=[[NSDateComponents alloc] init];

[components setYear:1900];

pickerView.datePicker.minimumDate = [[NSCalendar currentCalendar] dateFromComponents:components];
pickerView.datePicker.maximumDate=[NSDate date]

It is restricting the dates, but it is allowing the user to scroll to the future dates as well as past dates. How can I hide or avoid them?

I am able to see that feature in the contacts app on the iPad. To see go to Contacts --> press the "+" symbol on top, then press on add birthday button.

解决方案

it scroll but visible on gray color, but it is not selectable, it is not possible to stop on scroll

To Disable Past date :

 pickerView.datePicker.minimumDate=[NSDate date];

To Disable Future date :

pickerView.datePicker.maximumDate=[NSDate date];

if you need this compulsory in your app you need to try on some 3rdparty app like this

这篇关于如何在UIDatePickerView中隐藏未来或过去的日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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