UIdatepicker showing weekdays

房东的猫 提交于 2019-12-11 01:49:13

问题


I would like to make a datepicker that shows weekdays, date and month.

I got a working datepicker showing month, date and year but I would really like it to show month, day, date

How is this possible? I know I might have to make a custom UIpicker, but how to I make this refer to dates?


回答1:


You need to create your own picker with a UIPickerView. Create an NSDateFormatter. You can then access the month names and the weekday names from the date formatter. An NSCalendar can be used to obtain the maximum number of days for a month.

The real trick is updating the picker view components as the user selects a value from one of the components. For example, if the user picks a month, you want to update the number of days shown in the day component (or, like a UIDatePicker), grey out invalid days. This is complicated by the fact that you don't have a year so there is no way to properly handle February.

And what do you do when a user picks a given weekday? How should this affect the selected day? Just things to consider.



来源:https://stackoverflow.com/questions/12959267/uidatepicker-showing-weekdays

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