Remove the “Today” entry from UIDatePicker

前端 未结 1 1988
后悔当初
后悔当初 2021-01-24 15:57

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.

相关标签:
1条回答
  • 2021-01-24 16:38

    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.
    0 讨论(0)
提交回复
热议问题