priya
priya

Reputation: 315

Customising Date Picker in Xcode

How can I customize a UIDatePicker to only show the month and year? There's an existing mode that shows the day, month, and year, but I'd like to get rid of the day portion.

Upvotes: 3

Views: 3505

Answers (2)

Dave DeLong
Dave DeLong

Reputation: 243156

Simply put, you can't. UIDatePicker does not have any API for only showing years and months.

You therefore have 3 possible recourses:

  1. Make your own out of a UIPickerView
  2. Use a UIDatePicker in Date mode and just ignore the day portion
  3. File a bug asking for this capability and hope it gets added at some point

I vote for #1 and #3.

Upvotes: 2

Sree
Sree

Reputation: 907

It is not Possible to customize the date picker like you need in the nib file.You can set the mode in nib to get only date or time or both.In this case you need to format your date to the required format using dateFormatter.For this you can set the format to "yyyy-MMM",which will returns you the year and month.

eg:

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MMM"];
NSString *formattedDate = [dateFormatter stringFromDate:date];
[dateFormatter release];

Upvotes: 0

Related Questions