Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I want to mark several dates in a month with an Array #20

Open
ygoez opened this issue Jul 11, 2013 · 1 comment
Open

I want to mark several dates in a month with an Array #20

ygoez opened this issue Jul 11, 2013 · 1 comment

Comments

@ygoez
Copy link

ygoez commented Jul 11, 2013

If i have several dates to mark in a month, it marks only the last date!!?? Please Help

here is the code:

-(void)calendarView:(VRGCalendarView *)calendarView switchedToMonth:(int)month targetHeight:(float)targetHeight animated:(BOOL)animated {
NSArray *test = [NSArray arrayWithObjects:@"2013-07-22",@"2013-07-23",@"2013-08-09",nil];

NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"yyyy-MM-dd"];


NSCalendar *gregorian = [[NSCalendar alloc]
                         initWithCalendarIdentifier:NSGregorianCalendar];

for (int i=0; i<test.count;i++){
     NSDate *mydate = [dateFormat dateFromString:[test objectAtIndex:i]];
     NSDateComponents *components = [gregorian components:NSMonthCalendarUnit fromDate:mydate];

if (month == components.month) {
    NSArray *date = [NSArray arrayWithObjects:mydate, nil];
    NSArray *color = [NSArray arrayWithObjects:[UIColor redColor],nil];
    [calendarView markDates:date withColors:color];
    }
}

}

@johnpaulmanoza
Copy link

I know this question was asked long time ago. But I don't think this is a problem about the library. Calendar marked the last date because -markDates was called only once. Please refer to the code below.

 __block NSMutableArray *dateMarkers = [[NSMutableArray alloc] init];
 __block NSMutableArray *dateMarkersColor = [[NSMutableArray alloc] init];

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
    NSArray *test = [NSArray arrayWithObjects:@"2013-07-22",@"2013-07-23",@"2013-08-09",nil];

    NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
    [dateFormat setDateFormat:@"yyyy-MM-dd"];

    NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];

    for (int i=0; i<test.count;i++){
        NSDate *mydate = [dateFormat dateFromString:[test objectAtIndex:i]];
        NSDateComponents *components = [gregorian components:NSMonthCalendarUnit fromDate:mydate];

        if (month == components.month) {
            [dateMarkers addObject:mydate];
            [dateMarkersColor addObject:[UIColor redColor]];
        }
    }

    dispatch_async(dispatch_get_main_queue(), ^{
        [calendarView markDates:dateMarkers withColors:dateMarkersColor];
    });
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants