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!