Reputation: 315
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
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:
UIPickerView
UIDatePicker
in Date mode and just ignore the day portionI vote for #1 and #3.
Upvotes: 2
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