iphoneiosxcodedatepickeruipickerview

How to block days in UIDatePicker for iOS


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.


Solution

  • 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.