johnvuko / JTCalendar

A customizable calendar view for iOS.
MIT License
2.76k stars 534 forks source link

Year view in JTCalendarMenuView? #230

Open SpencerMichaels opened 8 years ago

SpencerMichaels commented 8 years ago

I would like to have a calendar where the top bar displays the year as well as the month. Some time ago there seems to have been a way to do this, but I cannot find anything in the documentation or in JTCalendarMenuView.m that seems to relate to changing the display format now, at least without changing line 59 in JTCalendarDelegateManager.m:

text = [[dateFormatter standaloneMonthSymbols][currentMonthIndex - 1] capitalizedString];

Would it be possible to expose a method to change the format programmatically?

bernardkroes commented 8 years ago

Just put something like this in your delegate:

- (void)calendar:(JTCalendarManager *)calendar prepareMenuItemView:(UIView *)menuItemView date:(NSDate *)date
{
    NSString *text = nil;

    if(date){
        NSCalendar *the_calendar = calendar.dateHelper.calendar;
        NSDateComponents *comps = [the_calendar components:NSCalendarUnitYear|NSCalendarUnitMonth fromDate:date];
        NSInteger currentMonthIndex = comps.month;

        static NSDateFormatter *dateFormatter = nil;
        if(!dateFormatter){
            dateFormatter = [calendar.dateHelper createDateFormatter];
        }

        dateFormatter.timeZone = calendar.dateHelper.calendar.timeZone;
        dateFormatter.locale = calendar.dateHelper.calendar.locale;

        while(currentMonthIndex <= 0){
            currentMonthIndex += 12;
        }

        text = [[NSString alloc] initWithFormat:@"%@ %ld",[[dateFormatter standaloneMonthSymbols][currentMonthIndex - 1] capitalizedString], (long)comps.year];
    }
    [(UILabel *)menuItemView setText:text];
}
CaptainKurt commented 8 years ago

Does this still work for swift?

zuaaef commented 8 years ago

@CaptainKurt I just wound up using a swift calendar version -> https://cocoapods.org/pods/JTAppleCalendar