Remove the “Today” entry from UIDatePicker

2019-03-01 08:11发布

When using a UIDatePicker in iOS SDK, there is always an entry "Today" at the current date. That's useful in most cases, but where I need it, it's rather confusing.

Is there a way to:

a) disable the "today"-entry (use regular date instead), and have all entries look the same

or even better

b) disable the "today"-entry (use regular date instead), and color the next day in blue

Further more, the application is for private use only, it's not going to get distributed on the AppStore, which means I could use private APIs (I still would rather avoid them) and I don't need it to be backwards compatible. iOS 4 is fine.

1条回答
ら.Afraid
2楼-- · 2019-03-01 08:34

I had a similar problem with the UIDatePicker not matching my requirements exactly (in my case I needed a datepicker without a year wheel). Having a look at the UIDatePicker reference, it doesn't look like you can disable the today entry, so you might be forced to do what I did.

I used a UIPickerView and re-implemented the date selection functionality I needed with that. There are a few things you will need to do to implement your custom date picker:

  • Implement a UIPickerViewDataSource to set up row titles, dimensions and row counts.
  • Implement a UIPickerViewDelegate to handle events from your custom picker.
  • Make sure you update your day wheel when the month wheel changes so you get appropriate days for each month. UIDatePicker does this pretty seamlessly. With limited time, I just reload the picker when the month changes so the day counts match up.
查看更多
登录 后发表回答