jivesoftware / PDTSimpleCalendar

A simple Calendar / Date Picker for iOS using UICollectionView

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Delegate functions slow down the UI

dozel opened this issue · comments

Hey, love the calendar, looks super slick and very customizable. Unfortunately I noticed a visible slow down when using the delegate methods. When I comment them out, it works fine.

Here is what I have:

  • (BOOL)simpleCalendarView:(PDTSimpleCalenderView *)view shouldUseCustomColorsForDate:(NSDate *)date {
    return YES;
    }

  • (UIColor *)simpleCalendarView:(PDTSimpleCalenderView *)view textColorForDate:(NSDate *)date {
    NSString *result = [date compareDate];

    if ([_dates objectForKey:result]) {
    return [UIColor whiteColor];
    }
    else if ([today isEqualToString:result]) {
    return [UIColor whiteColor];
    }
    return [UIColor buddyNavyColor];
    }

  • (UIColor *)simpleCalendarView:(PDTSimpleCalenderView *)view circleColorForDate:(NSDate *)date {
    NSString *result = [date compareDate];

    if ([_dates objectForKey:result]) {
    return [UIColor buddyNavyColor];
    }
    else if ([today isEqualToString:result]) {
    return [UIColor lightGrayColor];
    }
    return [UIColor whiteColor];
    }

_dates is an NSMutableDictionary.

Let me know if I'm doing something that I'm not supposed to in these methods that can cause the slowdown.

commented
  1. Yes delegate methods will slow the calendar down a bit.
  2. You can optimize your delegate calls here.

In (BOOL)simpleCalendarView:(PDTSimpleCalenderView *)view shouldUseCustomColorsForDate:(NSDate *)date do not return YES.

Instead, I would do

(BOOL)simpleCalendarView:(PDTSimpleCalenderView *)view shouldUseCustomColorsForDate:(NSDate *)date {
    NSString *result = [date compareDate];
    return ([_dates objectForKey:result]);
}

Use the custom color ONLY for your specific cases instead of all the cells on the calendar

- (UIColor *)simpleCalendarView:(PDTSimpleCalenderView *)view textColorForDate:(NSDate *)date {
     return [UIColor whiteColor];
}

- (UIColor *)simpleCalendarView:(PDTSimpleCalenderView *)view circleColorForDate:(NSDate *)date {
    return [UIColor buddyNavyColor];
}

And for the default cells, change the colors using the appearance selector (this is copy/past from the README)

    [[PDTSimpleCalendarViewCell appearance] setCircleDefaultColor:[UIColor whiteColor]];
    [[PDTSimpleCalendarViewCell appearance] setCircleSelectedColor:[UIColor orangeColor]];
    [[PDTSimpleCalendarViewCell appearance] setCircleTodayColor:[UIColor blueColor]];
    [[PDTSimpleCalendarViewCell appearance] setTextDefaultColor:[UIColor redColor]];
    [[PDTSimpleCalendarViewCell appearance] setTextSelectedColor:[UIColor purpleColor]];
    [[PDTSimpleCalendarViewCell appearance] setTextTodayColor:[UIColor magentaColor]];
    [[PDTSimpleCalendarViewCell appearance] setTextDisabledColor:[UIColor yellowColor]];

You should see a performance increase by doing that.