Sti
Sti

Reputation: 8503

UIDatePicker, dates beyond maximum and minimum are still visible

The reference for UIDatePicker.maximumDate says the following:

maximumDate

The maximum date that a date picker can show.

The reference for minimumDate says the equivalent for minimum.

But when implementing maximumDate and minimumDate in an UIDatePicker, the picker still shows the maximum and the minimum dates. And way more. Actually, the UIDatePicker shows ALL dates. The only thing that has changed is that when you stop scrolling, it automatically scrolls you back to the min/max threshold. Is there a way to prevent dates before minimumDate and dates after maximumDate to ever appear? If I set the maximumDate to January 1st 2020, I don't want/need the user to be able to scroll beyond that just to be thrown back to this date. They can sit there scrolling and scrolling for minutes/hours if they want, and end up in the year 3000. And when they stop scrolling, it will revert to 2020. Why? I want the date picker to NOT SHOW the dates beyond min/max, and literally stop there. No more dates outside my range. I know this is possible with UIPicker, if I create it myself, but I feel this should be the default behavior when implementing min/max in this element.

Why is this not possible with UIDatePicker? Or is it?

Upvotes: 1

Views: 897

Answers (2)

kumarsiddharth123
kumarsiddharth123

Reputation: 209

It's not possible with UIDatePicker. I suggest implementing your own date picker by using an UIPickerView and populating the custom values.

Upvotes: 0

sanjeev
sanjeev

Reputation: 170

Sorry, but UIDatePicker doesn't support setting valid date ranges like you describe. The only option is prepare an array from calendar dates then pass it to picker.

Upvotes: 1

Related Questions