码迷,mamicode.com
首页 > 移动开发 > 详细

IOS之使用CKCalendar做datePicker

时间:2014-06-08 10:52:51      阅读:298      评论:0      收藏:0      [点我收藏+]

标签:ckcalendar   datepicker   ios   

比较符合项目需要,要做一个日历选择器,并且实现当前日期之后的时间不可选。网上找了一下,GitHub上的一个开源日历选择器CKCalendar比较符合项目需求。效果图如下:(很反感网上那些文章讲了半天连个效果图都没有,纯个人吐槽,勿喷~)

bubuko.com,布布扣

    刚开始对着CKCalendar的源码看来半天,还想着直接修改源码让当前日期之后的不可选,却忘了去测试作者提供的代理接口,真傻!

鼓捣半天后终于弄出来了,怕时间久了就忘了,还是做一下笔记:

当前日期之后不可选

#pragma mark - CalendarPickerDelegate Method
- (BOOL)calendar:(CKCalendarView *)calendar willSelectDate:(NSDate *)date
{
    NSDate *now = [NSDate date];
    NSString *stringNow = [DATE_FORMATER stringFromDate:now];
    now = [DATE_FORMATER dateFromString:stringNow];
    NSString *selectedValue;
    if ([date compare:now] == NSOrderedSame ||[date compare:now] == NSOrderedAscending) {
        _calendarPickerVC.selectedDate = date;
        selectedValue = [DATE_FORMATER stringFromDate:_calendarPickerVC.selectedDate];
        _evalItem.value0 = selectedValue;
        [_btnValue0ValueList setTitle:selectedValue forState:UIControlStateNormal];
        [self makeOtherItemValues];
    }
    else
        return NO;
    
    
    return YES;
    
}

- (void)calendar:(CKCalendarView *)calendar configureDateItem:(CKDateItem *)dateItem forDate:(NSDate *)date
{
    NSDate *now = [NSDate date];
    NSString *stringNow = [DATE_FORMATER stringFromDate:now];
    now = [DATE_FORMATER dateFromString:stringNow];
    if ([date compare:now]==NSOrderedDescending ) {
        dateItem.textColor = [UIColor lightGrayColor];
    }
    
}


当前日期之前不可选:

#pragma mark - CalendarPickerDelegate Menthod
- (BOOL)calendar:(CKCalendarView *)calendar willSelectDate:(NSDate *)date
{
    NSDate *now = [NSDate date];
    NSString *stringNow = [DATE_FORMATER stringFromDate:now];
    now = [DATE_FORMATER dateFromString:stringNow];
    NSString *selectedValue;
    if ([date compare:now] == NSOrderedSame ||[date compare:now] == NSOrderedDescending) {
        _calendarPickerVC.selectedDate = date;
        selectedValue = [DATE_FORMATER stringFromDate:_calendarPickerVC.selectedDate];
    }
    else
        return NO;
    
    
    return YES;
    
}

- (void)calendar:(CKCalendarView *)calendar configureDateItem:(CKDateItem *)dateItem forDate:(NSDate *)date
{
    NSDate *now = [NSDate date];
    NSString *stringNow = [DATE_FORMATER stringFromDate:now];
    now = [DATE_FORMATER dateFromString:stringNow];
    if ([date compare:now]==NSOrderedAscending ) {
        dateItem.textColor = [UIColor lightGrayColor];
    }
    
}


特别记得不要忘记设置代理: _calendarPickerVC.calendar.delegate = self;

完!

IOS之使用CKCalendar做datePicker,布布扣,bubuko.com

IOS之使用CKCalendar做datePicker

标签:ckcalendar   datepicker   ios   

原文地址:http://blog.csdn.net/chaoyuan899/article/details/28682667

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!