Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting the Datepicker in IOS to pick only the Month and Year

Is there any way possible to set a UIDatePicker in XCode-Interface Builder to just use the rollers of the "month" and "year" without the "day"? I've tried checking the file properties in the IB yet failed to find a solution for my problem...

like image 230
Paul John Parreno Avatar asked Jun 13 '11 08:06

Paul John Parreno


3 Answers

Your question mentions date and year so I it seemed like UIDatePickerModeDate would suffice but as you are looking for month and year which is not an available option. I suggest you consider using a two component UIPickerView object.

Original Answer

You can do this by changing the Mode property under Date Picker to Date in the Attributes Inspector in the right bar ( Cmd + Option + 4 ). You can also do this programmatically,

datePicker.datePickerMode = UIDatePickerModeDate;
like image 155
Deepak Danduprolu Avatar answered Nov 07 '22 12:11

Deepak Danduprolu


I don't think this is possible using the standard UIDatePicker. If you have a look at the documentation it makes it clear that only four modes are available:

  • UIDatePickerModeTime,
  • UIDatePickerModeDate,
  • UIDatePickerModeDateAndTime,
  • UIDatePickerModeCountDownTimer

You may have to create your own.

like image 39
gnuchu Avatar answered Nov 07 '22 13:11

gnuchu


You can use this Month and Year picker realization

like image 1
Igor Avatar answered Nov 07 '22 11:11

Igor