关于JTCalendar是一个很好的写日历的第三方,我们可已从http://www.code4app.com/ios/有农历的日历/5225b2f96803fa484f000000网址的到实例代码
下面我就介绍一下一些控制日历的代码
控制点击日历日期使选中日期变色的事件
[_calendarManager setDate:_todayDate];
控制小点标记的事件
if([self haveEventForDay:dayView.date]){
dayView.dotView.hidden = NO;
}
else{
dayView.dotView.hidden = YES;
}
}
- (BOOL)haveEventForDay:(NSDate *)date
{
NSString *key = [[self dateFormatter] stringFromDate:date];
if(_eventsByDate[key] && [_eventsByDate[key] count] > 0){
return YES;
}
return NO;
}
超出当前日期跳转下一月
if(![_calendarManager.dateHelper date:_calendarContentView.date isTheSameMonthThan:dayView.date]){
if([_calendarContentView.date compare:dayView.date] == NSOrderedAscending){
[_calendarContentView loadNextPageWithAnimation];
}
else{
[_calendarContentView loadPreviousPageWithAnimation];
}
}
控制点击颜色和当前日期颜色
- (void)calendar:(JTCalendarManager *)calendar prepareDayView:(JTCalendarDayView *)dayView
控制点击事件
-(void)calendar:(JTCalendarManager *)calendar didTouchDayView:(JTCalendarDayView *)dayView{
日期转string
NSDateFormatter *dateformatter = [[NSDateFormatter alloc]init];
[dateformatter setDateFormat:@"yyyy-MM-dd"];
NSString *dateStr = [dateformatter stringFromDate:dayView.date];