OGeek|极客世界-中国程序员成长平台

标题: iphone - 如何在 iOS 的 UIDatePicker 中阻止天数 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 22:38
标题: iphone - 如何在 iOS 的 UIDatePicker 中阻止天数

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

谢谢。



Best Answer-推荐答案


您唯一能做的就是添加自定义 UIPickerView,如注释中所述,或实现为事件 UIControlEventValueChanged 调用的方法,如 here 所述

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

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

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

关于iphone - 如何在 iOS 的 UIDatePicker 中阻止天数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12206336/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4