Remove the “Today” entry from UIDatePicker

无人久伴 提交于 2019-12-04 05:15:21

问题


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:


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.


来源:https://stackoverflow.com/questions/4220850/remove-the-today-entry-from-uidatepicker

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!