UIdatepicker显示平日 [英] UIdatepicker showing weekdays

查看:122
本文介绍了UIdatepicker显示平日的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想制作一个显示工作日,日期和月份的日期戳。



我有一个工作的日期显示器显示月,日期和年份,但我真的很喜欢显示月,日,日期



这可能如何?我知道我可能需要制作一个自定义的UIpicker,但是如何让它引用日期?

解决方案

你需要创建您自己的选择器与UIPickerView。创建一个NSDateFormatter。然后,您可以从日期格式化程序访问月份名称和工作日名称。可以使用NSCalendar来获取一个月的最长天数。



真正的技巧是更新选择器视图组件,因为用户从组件。例如,如果用户选择一个月,您想要更新天组件中显示的天数(或者像UIDatePicker),则会显示无效天数。这是一个复杂的事实,你没有一年,所以没有办法正确处理二月。



当用户选择一个给定的工作日?这应该如何影响选定的一天?只需要考虑。


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?

解决方案

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.

这篇关于UIdatepicker显示平日的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆