iOS use Ckcalendar do DatePicker

Source: Internet
Author: User

Compared to the project needs, to make a calendar selector, and the implementation of the current date after the time is not selectable. On the Internet, an open source calendar selector on GitHub Ckcalendar more in line with project requirements. as follows: (very disgusted with those articles on the internet for half a day even without, pure personal spit groove, do not spray ~)


At the beginning of the Ckcalendar source seems to be half a day, but also want to directly modify the source code so that the current date is not optional, but forgot to test the agent interface provided by the author, really silly!

Tinker after a half-day finally out, afraid of time to forget, or do a note:

not selectable after the current date :

#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]; }    }


Not selectable before the current date:

#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]; }    }


Remember not to forget to set up a proxy: _calendarpickervc. Calendar. Delegate = Self;

Finish!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.