jaykz52 / CKCalendar

A sleek, easily customized calendar control for iOS.
www.cozykozy.com
634 stars 179 forks source link

Modifying DateButton to create an event #49

Open jaime-fuhr opened 11 years ago

jaime-fuhr commented 11 years ago

I added the following code to CKCalendarView to create an event for a specific date.

-(void)setEventForDate:(NSDate *)date isHoliday:(BOOL)holiday withTitle:(NSString *)title{

   // NSLog(@"Date received for event %@", date);

    for (DateButton *dateButton in self.dateButtons) {
        if (dateButton.date) {
            NSLog(@"%@", dateButton.date);

            if ([date isEqualToDate:dateButton.date]) {
                NSLog(@"Matched date %@", dateButton.date);

                UIColor *eventColor;
                UIColor *textColor;

                if (holiday) {
                    eventColor = [UIColor grayColor];
                    textColor = [UIColor whiteColor];
                } else {
                    eventColor =[UIColor colorWithRed:0.557 green:0.137 blue:0.267 alpha:1];
                    textColor = [UIColor whiteColor];
                }

                UILabel *eventTitle = [[UILabel alloc] initWithFrame:CGRectMake(0, dateButton.frame.size.height - 15, dateButton.frame.size.width, 15)];

                [eventTitle setNumberOfLines:0];
                [eventTitle setText:title];
                [eventTitle setTextColor: textColor];
                [eventTitle setBackgroundColor:eventColor];
                [eventTitle setAdjustsFontSizeToFitWidth:YES];
                [eventTitle setTextAlignment:NSTextAlignmentCenter];

                [dateButton addSubview:eventTitle];
            }

        }
    }
}

The trouble I am having is that the the view shows in the cell the day before the correct date.

For example, if date passed in is 10/20/2013, the UILabel appears in the cell for 10/19, even though the debugger shows that the dateButton is 10/20.

I've narrowed it down to onlyShowCurrentMonth. If set to YES, the view appears in the correct cell otherwise it shows up in the day before.

sudhakar-448 commented 8 years ago

in this what is the date button ?

sudhakar-448 commented 8 years ago

and what is the date buttons array?