How to hide some of the years in UIDatePicker in Swift?

1.9k Views Asked by At

I need to restrict the years in UIDatePicker, i.e set year is hidden if the year is more than our maximum date.

For this I already tried like myDatePicker.maximumDate=NSDate()

My date picker like UIDatePickerView

Now how can I remove or hide the year values more than(i.e 2016) our maximum date.

Thankyou

2

There are 2 best solutions below

1
On

If that is really what you want - I think you have to build a custom picker yourself using UIPickerView.

Per iOS docs, "The appearance of UIDatePicker is not customizable."

2
On

you need to set validation on picker. so set the maximum date and minimum date of picker. ////

 self.datePicker.minimumDate = minDate;
    self.datePicker.maximumDate = maxDate;