如何在 iOS 的 UIDatePicker 中阻止天数 [英] How to block days in UIDatePicker for iOS

查看:21
本文介绍了如何在 iOS 的 UIDatePicker 中阻止天数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的 IOS 应用程序上使用日期选择器,我想知道是否可以阻止几天.例如,我需要屏蔽一年中的所有星期一,这可能吗?

谢谢.

解决方案

你唯一能做的就是添加一个自定义的 UIPickerView 如注释中所述或实现一个为事件调用的方法 UIControlEventValueChanged此处 所述>

然后检查有效工作日的新值.您可以通过以下方式获得工作日:

NSCalendar* calendar = [NSCalendar currentCalendar];NSDateComponents* components = [日历组件:NSWeekdayCalendarUnit fromDate:[NSDate date]];返回[组件工作日];//1 = 星期日,2 = 星期一,...

无法在滚轮中隐藏某些日子.

I'm using a Date picker on my IOS app, and I want to know if is possible to block some days. For example, I need to block all mondays from a year, is this possible?

Thanks.

解决方案

The only thing you can do is add a custom UIPickerView as described in the comments or implement a method that is called for the event UIControlEventValueChanged as described here

then check the new value for a valid weekday. you can get the weekday with:

NSCalendar* calendar = [NSCalendar currentCalendar];
NSDateComponents* components = [calendar components:NSWeekdayCalendarUnit fromDate:[NSDate date]];
return [components weekday]; // 1 = Sunday, 2 = Monday, ...

There is no way to hide some days in the scrollwheel.

这篇关于如何在 iOS 的 UIDatePicker 中阻止天数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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