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

Added Multiple Select Dates #53

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Examples/Calendar/CKViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
1 change: 1 addition & 0 deletions Source/CKCalendarView.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
12 changes: 12 additions & 0 deletions Source/CKCalendarView.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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];

Expand Down Expand Up @@ -415,6 +423,10 @@ - (void)reloadDates:(NSArray *)dates {
[self setNeedsLayout];
}

- (void)selectDates:(NSArray *)datesToSelect{
[self.datesToBeSelected addObjectsFromArray:datesToSelect];
}

- (void)_setDefaultStyle {
self.backgroundColor = UIColorFromRGB(0x393B40);

Expand Down