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

78,410

Solution 1

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;

Solution 2

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.

Solution 3

You can use this Month and Year picker realization

Share:
78,410
BearDroid
Author by

BearDroid

Updated on July 16, 2022

Comments

  • BearDroid
    BearDroid almost 2 years

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

  • BearDroid
    BearDroid about 13 years
    Thanks Deepak, but this mode shows the "day" roller as well... I would like to only display the Month and Year.
  • patrick-fitzgerald
    patrick-fitzgerald over 11 years
    UIDatePickerModeDate - Displays month, day, and year depending on the locale setting (e.g. November | 15 | 2007)
  • iFateh
    iFateh about 2 years
    @PaulJohnParreno Hello, Have You Found solution on How to show only Year or Month ?