Ganesh Kumar
Ganesh Kumar

Reputation: 726

how to implement Calendar view in two weeks mode(Used JTCalendar example)

enter image description here I have implemented JTCalendar view to get both month and week view but in week view,i need to get two week view .Suggest me coding.

JTCalendar code:

CGFloat x = 0;
CGFloat width = self.frame.size.width / 7.;

CGFloat height = self.frame.size.height;

if(self.calendarManager.calendarAppearance.readFromRightToLeft)
{
    for(UIView *view in [[self.subviews reverseObjectEnumerator] allObjects])
    {
        view.frame = CGRectMake(x, 0, width, height);
        x = CGRectGetMaxX(view.frame);
    }
}
else{
    for(UIView *view in self.subviews)
    {
        view.frame = CGRectMake(x, 0, width, height);
        x = CGRectGetMaxX(view.frame);
    }
}

[super layoutSubviews];

#//weeksToDisplay

  • (void)configureConstraintsForSubviews
{
CGFloat weeksToDisplay;

if(cacheLastWeekMode)
{
    weeksToDisplay = 1 ;
}
else{
    weeksToDisplay = (CGFloat)(WEEKS_TO_DISPLAY + 1); // + 1 for weekDays
}

CGFloat y = 0;
CGFloat width = self.frame.size.width;
CGFloat height = self.frame.size.height / weeksToDisplay;

for(int i = 0; i < self.subviews.count; ++i){
    UIView *view = self.subviews[i];

    view.frame = CGRectMake(0, y, width, height);
    y = CGRectGetMaxY(view.frame);

    if(cacheLastWeekMode && i == weeksToDisplay + 1){
        height = 0.;
    }
}
}

Upvotes: 3

Views: 1769

Answers (3)

Ganesh Kumar
Ganesh Kumar

Reputation: 726

enter image description here

- (void)setBeginningOfMonth:(NSDate *)date
{
  NSDate *currentDate = date;

NSCalendar *calendar = self.calendarManager.calendarAppearance.calendar;

{
    NSDateComponents *comps = [calendar components:NSCalendarUnitMonth|NSCalendarUnitDay fromDate:currentDate];

    currentMonthIndex = comps.month;
    // Hack
    if(comps.day >7)
    {
        currentMonthIndex = (currentMonthIndex % 12) + 1;
    }
}

for(JTCalendarWeekView *view in weeksViews)
{
    view.currentMonthIndex = currentMonthIndex;
    [view setBeginningOfWeek:currentDate];

    NSDateComponents *dayComponent = [NSDateComponents new];
    dayComponent.day = 7;

    currentDate = [calendar dateByAddingComponents:dayComponent toDate:currentDate options:0];

    // Doesn't need to do other weeks
//        if(self.calendarManager.calendarAppearance.isWeekMode)
   //        {
   //            break;
 //        }
   }
 }

Upvotes: 0

bhargavisridharan
bhargavisridharan

Reputation: 207

In MonthView Change Weeks to display as 3 also do this comment the following code in delegate method setBeginingofmonth

 for(JTCalendarWeekView *view in weeksViews)
{
    view.currentMonthIndex = currentMonthIndex;
    [view setBeginningOfWeek:currentDate];

    NSDateComponents *dayComponent = [NSDateComponents new];
    dayComponent.day = 7;

    currentDate = [calendar dateByAddingComponents:dayComponent toDate:currentDate options:0];

    // Doesn't need to do other weeks
//        if(self.calendarManager.calendarAppearance.isWeekMode)
//        {
//            break;
//        }
    }

in JTCalendar updatePage method change 7 to 14 as below

 if(!self.calendarAppearance.isWeekMode)
{
    dayComponent.month = currentPage - (NUMBER_PAGES_LOADED / 2);
}
else
{
    //to show next starting week for two weeks mode put 14
    dayComponent.day = 14 * (currentPage - (NUMBER_PAGES_LOADED / 2));
}

Upvotes: 1

Ganesh Kumar
Ganesh Kumar

Reputation: 726

change the weeksToDisplay.enter image description here

if(cacheLastWeekMode)
{
weeksToDisplay = 3 ;
}   

Upvotes: 1

Related Questions