diff --git a/Examples/Calendar/CKViewController.m b/Examples/Calendar/CKViewController.m index 9d50374..7e3a534 100644 --- a/Examples/Calendar/CKViewController.m +++ b/Examples/Calendar/CKViewController.m @@ -33,6 +33,13 @@ - (id)init { calendar.onlyShowCurrentMonth = NO; calendar.adaptHeightToNumberOfWeeksInMonth = YES; + + //Example for multiple selected dates + + [self.calendar selectDates:[[NSArray alloc] initWithObjects: + [self.dateFormatter dateFromString:@"5/12/2013"], + [self.dateFormatter dateFromString:@"6/12/2013"], + [self.dateFormatter dateFromString:@"7/12/2013"], nil]]; calendar.frame = CGRectMake(10, 10, 300, 320); [self.view addSubview:calendar]; diff --git a/Source/CKCalendarView.h b/Source/CKCalendarView.h index 4615c5a..d7de00d 100644 --- a/Source/CKCalendarView.h +++ b/Source/CKCalendarView.h @@ -58,6 +58,7 @@ typedef enum { - (void)setDayOfWeekBottomColor:(UIColor *)bottomColor topColor:(UIColor *)topColor; - (void)selectDate:(NSDate *)date makeVisible:(BOOL)visible; +- (void)selectDates:(NSArray *)datesToSelect; - (void)reloadData; - (void)reloadDates:(NSArray *)dates; diff --git a/Source/CKCalendarView.m b/Source/CKCalendarView.m index e79e5ac..338a13c 100644 --- a/Source/CKCalendarView.m +++ b/Source/CKCalendarView.m @@ -113,12 +113,14 @@ @interface CKCalendarView () @property(nonatomic, strong) NSArray *dayOfWeekLabels; @property(nonatomic, strong) NSMutableArray *dateButtons; @property(nonatomic, strong) NSDateFormatter *dateFormatter; +@property(nonatomic,strong) NSMutableArray *datesToBeSelected; @property (nonatomic, strong) NSDate *monthShowing; @property (nonatomic, strong) NSDate *selectedDate; @property (nonatomic, strong) NSCalendar *calendar; @property(nonatomic, assign) CGFloat cellWidth; + @end @implementation CKCalendarView @@ -147,6 +149,8 @@ - (void)_init:(CKCalendarStartDay)firstDay { self.onlyShowCurrentMonth = YES; self.adaptHeightToNumberOfWeeksInMonth = YES; + self.datesToBeSelected = [[NSMutableArray alloc] init]; + self.layer.cornerRadius = 6.0f; UIView *highlight = [[UIView alloc] initWithFrame:CGRectZero]; @@ -317,6 +321,10 @@ - (void)layoutSubviews { [dateButton setTitleColor:item.textColor forState:UIControlStateNormal]; dateButton.backgroundColor = item.backgroundColor; } + + if([self.datesToBeSelected containsObject:date]){ + dateButton.backgroundColor = item.selectedBackgroundColor; + } dateButton.frame = [self _calculateDayCellFrame:date]; @@ -415,6 +423,10 @@ - (void)reloadDates:(NSArray *)dates { [self setNeedsLayout]; } +- (void)selectDates:(NSArray *)datesToSelect{ + [self.datesToBeSelected addObjectsFromArray:datesToSelect]; +} + - (void)_setDefaultStyle { self.backgroundColor = UIColorFromRGB(0x393B40);