How to hide future or past dates in UIDatePickerView

I want to create a user interface for setting a date of birth. For this I choose UIDatePickerView. Now I want to limit the dates between 01-01-1990 and the current date. It should not show future dates and past dates. I am currently 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 limits dates, but allows the user to scroll through future dates as well as past dates. How can I hide or avoid them?

I can see this feature in the contact application on the iPad. To go to "Contacts" → click the "+" icon on the top, then click the add birthday button.

+4
source share
2 answers

, , ,

,

:

 pickerView.datePicker.minimumDate=[NSDate date];

:

pickerView.datePicker.maximumDate=[NSDate date];

, - 3rdparty, this

+3

, :

let now = Date();
pickerviewOutletname.maximumDate = now

, :

let now = Date();
pickerviewOutletname.minimumDate = now
0

Source: https://habr.com/ru/post/1611439/


All Articles