1

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

WeCan
  • 547
  • 2
  • 9
  • 23
  • If it is set as the maximum date, users won't be able to scroll beyond that (it will just go back to the maximum date). This is the behaviour of the UIDatePicker. Why do you need to hide the dates beyond that? – William GP May 26 '16 at 09:54
  • @WilliamGP thank you for immediate reply. Suppose with out hiding the year values beyond maximum date then user try scroll year component that's why I want to show year component upto maximum date only. – WeCan May 26 '16 at 10:04
  • Yes, but it will just automatically scroll back to the maximum date. – William GP May 26 '16 at 10:04
  • @WilliamGP thank you for your reply again. Automatically scroll back to the maximum date is working fine for me this is not my problem. I need to hide the beyond the dates(i.e minimum date and maximum date) – WeCan May 26 '16 at 10:12
  • If that is really what you want - I think you have to build a custom picker yourself using UIPickerView. Per iOS docs, " You cannot customise the appearance of Date Pickers" - https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/UIKitUICatalog/UIDatePicker.html#//apple_ref/doc/uid/TP40012857-UIDatePicker-SW3 – William GP May 26 '16 at 10:34
  • @WilliamGP sorry for lately reply and thank you for this info. Now I will work on that. – WeCan May 26 '16 at 10:47

2 Answers2

1

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."

Michal Šrůtek
  • 1,647
  • 16
  • 17
William GP
  • 1,252
  • 1
  • 14
  • 29
  • thank you for your suggestion. I will post my code as soon as Now I am working on it. THANK YOU – WeCan May 27 '16 at 05:19
0

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;
  • ankit thank you for immediate reply. I already set min 01/01/2011 and max date is currentdate in storybaord. But still beyond the dates are showing in date picker so how can I hide/remove that dates. – WeCan May 26 '16 at 10:04
  • welcome if its work than please upword my answer and accept it. – Chaudhary Ankit Deshwal May 26 '16 at 10:07