JTCalendar
JTCalendar copied to clipboard
Dynamic Height of Calendar View
how to change calendar between 4 lines or 5 lines according to the number of days in month.
- In JTCalendarDelegate.h file add
- (NSUInteger)numberOfWeeksRowInMonth:(NSDate *)currentDate;
- In JTCalendarDelegateManager.h add
- (NSUInteger)numberOfWeeksRow:(NSDate *)currentDate;
- In JTCalendarDelegateManager.m add
- (NSUInteger)numberOfWeeksRow:(NSDate *)currentDate {
if(_manager.delegate && [_manager.delegate respondsToSelector:@selector(numberOfWeeksRowInMonth:)]){
return [_manager.delegate numberOfWeeksRowInMonth:currentDate];
}
return _manager.settings.pageViewNumberOfWeeks;
}
- In JTCalendarPageView.m file, inside - (void)reload, replace
_numberOfWeeksDisplayed = MIN(_manager.settings.pageViewNumberOfWeeks, MAX_WEEKS_BY_MONTH);
with_numberOfWeeksDisplayed = MIN([_manager.delegateManager numberOfWeeksRow:_date], MAX_WEEKS_BY_MONTH);
- In JTCalendarPageView.m file, inside - (void)reload , add below statement at the end of the function
[self layoutSubviews];
And In Your Controller, implement
func numberOfWeeksRow(inMonth currentDate: Date!) -> UInt {
//calcuate numberOFweeksInMonth of currentDate and return.
}
Also implement calendarDidLoadNextPage, calendarDidLoadPreviousPage delegates to change the height of your calendarView (JTHorizontalCalendarView) as per numberOFweeksInMonth in calendar.date()