From 75eed43cc39704ebe11a37cd50460723dde710f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E8=89=AF=E5=B1=80?= Date: Mon, 24 Oct 2016 10:35:57 +0800 Subject: [PATCH] Indicate the next/previous page with the selete date and mark it(default is 1st). --- Example/Example/CustomViewController.m | 13 +++++++++++++ JTCalendar/JTCalendarDelegate.h | 7 +++++++ JTCalendar/Managers/JTCalendarDelegateManager.h | 3 +++ JTCalendar/Managers/JTCalendarDelegateManager.m | 8 ++++++++ JTCalendar/Views/JTHorizontalCalendarView.m | 2 ++ JTCalendar/Views/JTVerticalCalendarView.m | 2 ++ 6 files changed, 35 insertions(+) diff --git a/Example/Example/CustomViewController.m b/Example/Example/CustomViewController.m index 21c4a41..db6fbbd 100644 --- a/Example/Example/CustomViewController.m +++ b/Example/Example/CustomViewController.m @@ -50,6 +50,19 @@ - (void)viewDidLoad #pragma mark - CalendarManager delegate +- (void)calendar:(JTCalendarManager *)calendar didLoadCalendar:(NSDate *)currentDate { + + BOOL isCurrentMonth = [_calendarManager.dateHelper date:currentDate isTheSameMonthThan:[NSDate date]]; + if (isCurrentMonth) { + _dateSelected = [NSDate date]; + } else { + _dateSelected = [_calendarManager.dateHelper firstDayOfMonth:currentDate]; + } + NSLog(@"%s == currentDate = %@", __FUNCTION__, currentDate); + +} + + // Exemple of implementation of prepareDayView method // Used to customize the appearance of dayView - (void)calendar:(JTCalendarManager *)calendar prepareDayView:(JTCalendarDayView *)dayView diff --git a/JTCalendar/JTCalendarDelegate.h b/JTCalendar/JTCalendarDelegate.h index 9e1348b..d6635ac 100644 --- a/JTCalendar/JTCalendarDelegate.h +++ b/JTCalendar/JTCalendarDelegate.h @@ -66,6 +66,13 @@ */ - (void)calendarDidLoadNextPage:(JTCalendarManager *)calendar; + +/*! + * Indicate the next/previous page with the selete date and mark it(default is 1st). + */ +- (void)calendar:(JTCalendarManager *)calendar didLoadCalendar:(NSDate *)currentDate; + + /*! * Provide a view conforming to `JTCalendarPage` protocol, used as page for the contentView. * Return an instance of `JTCalendarPageView` by default. diff --git a/JTCalendar/Managers/JTCalendarDelegateManager.h b/JTCalendar/Managers/JTCalendarDelegateManager.h index 321a343..101a13d 100644 --- a/JTCalendar/Managers/JTCalendarDelegateManager.h +++ b/JTCalendar/Managers/JTCalendarDelegateManager.h @@ -29,6 +29,9 @@ - (NSDate *)dateForPreviousPageWithCurrentDate:(NSDate *)currentDate; - (NSDate *)dateForNextPageWithCurrentDate:(NSDate *)currentDate; +//default is 1st +- (void)didLoadCurrentMonthSeletedDayWithCurrentDate:(NSDate *)currentDate; + // Page view - (UIView *)buildWeekDayView; diff --git a/JTCalendar/Managers/JTCalendarDelegateManager.m b/JTCalendar/Managers/JTCalendarDelegateManager.m index 1bda553..f0631dd 100644 --- a/JTCalendar/Managers/JTCalendarDelegateManager.m +++ b/JTCalendar/Managers/JTCalendarDelegateManager.m @@ -114,6 +114,14 @@ - (NSDate *)dateForNextPageWithCurrentDate:(NSDate *)currentDate } } +- (void)didLoadCurrentMonthSeletedDayWithCurrentDate:(NSDate *)currentDate { + NSAssert(currentDate != nil, @"currentDate cannot be nil"); + + if(_manager.delegate && [_manager.delegate respondsToSelector:@selector(calendar:didLoadCalendar:)]){ + [_manager.delegate calendar:self.manager didLoadCalendar:currentDate]; + } +} + #pragma mark - Page view - (UIView *)buildWeekDayView diff --git a/JTCalendar/Views/JTHorizontalCalendarView.m b/JTCalendar/Views/JTHorizontalCalendarView.m index ad5b20c..e9cb129 100644 --- a/JTCalendar/Views/JTHorizontalCalendarView.m +++ b/JTCalendar/Views/JTHorizontalCalendarView.m @@ -160,6 +160,7 @@ - (void)loadNextPageWithAnimation - (void)loadPreviousPage { + [_manager.delegateManager didLoadCurrentMonthSeletedDayWithCurrentDate:_rightView.date]; NSDate *nextDate = [_manager.delegateManager dateForPreviousPageWithCurrentDate:_leftView.date]; // Must be set before chaging date for PageView for updating day views @@ -240,6 +241,7 @@ - (void)loadPreviousPage - (void)loadNextPage { + [_manager.delegateManager didLoadCurrentMonthSeletedDayWithCurrentDate:_rightView.date]; NSDate *nextDate = [_manager.delegateManager dateForNextPageWithCurrentDate:_rightView.date]; // Must be set before chaging date for PageView for updating day views diff --git a/JTCalendar/Views/JTVerticalCalendarView.m b/JTCalendar/Views/JTVerticalCalendarView.m index 525274b..0a91548 100644 --- a/JTCalendar/Views/JTVerticalCalendarView.m +++ b/JTCalendar/Views/JTVerticalCalendarView.m @@ -160,6 +160,7 @@ - (void)loadNextPageWithAnimation - (void)loadPreviousPage { + [_manager.delegateManager didLoadCurrentMonthSeletedDayWithCurrentDate:_rightView.date]; NSDate *nextDate = [_manager.delegateManager dateForPreviousPageWithCurrentDate:_leftView.date]; // Must be set before chaging date for PageView for updating day views @@ -240,6 +241,7 @@ - (void)loadPreviousPage - (void)loadNextPage { + [_manager.delegateManager didLoadCurrentMonthSeletedDayWithCurrentDate:_rightView.date]; NSDate *nextDate = [_manager.delegateManager dateForNextPageWithCurrentDate:_rightView.date]; // Must be set before chaging date for PageView for updating day views