diff --git a/DSLCalendarView/DSLCalendarDayView.h b/DSLCalendarView/DSLCalendarDayView.h index 2d3f857..563df66 100644 --- a/DSLCalendarView/DSLCalendarDayView.h +++ b/DSLCalendarView/DSLCalendarDayView.h @@ -51,6 +51,7 @@ enum { @property (nonatomic, assign) DSLCalendarDayViewPositionInWeek positionInWeek; @property (nonatomic, assign) DSLCalendarDayViewSelectionState selectionState; @property (nonatomic, assign, getter = isInCurrentMonth) BOOL inCurrentMonth; +@property (nonatomic, assign) BOOL isCurrentDay; @property (nonatomic, strong, readonly) NSDate *dayAsDate; diff --git a/DSLCalendarView/DSLCalendarDayView.m b/DSLCalendarView/DSLCalendarDayView.m index 7db4029..bdf42c4 100644 --- a/DSLCalendarView/DSLCalendarDayView.m +++ b/DSLCalendarView/DSLCalendarDayView.m @@ -114,6 +114,9 @@ - (void)drawBackground { else { [[UIColor colorWithWhite:225.0/255.0 alpha:1.0] setFill]; } + if(_isCurrentDay) { + [[UIColor colorWithRed:0x08/255.0 green:0x7D/255.0 blue:0xE8/255.0 alpha:1.0] setFill]; + } UIRectFill(self.bounds); } else { diff --git a/DSLCalendarView/DSLCalendarMonthView.m b/DSLCalendarView/DSLCalendarMonthView.m index 6e69210..51c12eb 100644 --- a/DSLCalendarView/DSLCalendarMonthView.m +++ b/DSLCalendarView/DSLCalendarMonthView.m @@ -119,6 +119,10 @@ - (void)createDayViews { dayView.positionInWeek = DSLCalendarDayViewMidWeek; break; } + + if([self isToday:day]) { + dayView.isCurrentDay = YES; + } [self.dayViewsDictionary setObject:dayView forKey:[self dayViewKeyForDay:day]]; [self addSubview:dayView]; @@ -142,6 +146,20 @@ - (void)createDayViews { self.frame = fullFrame; } +- (BOOL) isToday:(NSDateComponents*)components { + NSCalendar *calendar = [NSCalendar currentCalendar]; + NSInteger comps = (NSDayCalendarUnit | NSMonthCalendarUnit | NSYearCalendarUnit); + + NSDateComponents *date2Components = [calendar components:comps fromDate:[NSDate new]]; + + NSDate *date1 = [calendar dateFromComponents:components]; + NSDate *date2 = [calendar dateFromComponents:date2Components]; + + NSComparisonResult result = [date1 compare:date2]; + + return result != NSOrderedAscending && result != NSOrderedDescending; +} + - (void)updateDaySelectionStatesForRange:(DSLCalendarRange*)range { for (DSLCalendarDayView *dayView in self.dayViews) { if ([range containsDate:dayView.dayAsDate]) { diff --git a/DSLCalendarView/DSLCalendarView.h b/DSLCalendarView/DSLCalendarView.h index a1caca5..289a11f 100644 --- a/DSLCalendarView/DSLCalendarView.h +++ b/DSLCalendarView/DSLCalendarView.h @@ -41,6 +41,7 @@ @property (nonatomic, copy) NSDateComponents *visibleMonth; @property (nonatomic, strong) DSLCalendarRange *selectedRange; @property (nonatomic, assign) BOOL showDayCalloutView; +@property (nonatomic, assign) BOOL allowRangeSelect; + (Class)monthSelectorViewClass; + (Class)monthViewClass; diff --git a/DSLCalendarView/DSLCalendarView.m b/DSLCalendarView/DSLCalendarView.m index 13a62ff..df53f9f 100644 --- a/DSLCalendarView/DSLCalendarView.m +++ b/DSLCalendarView/DSLCalendarView.m @@ -421,6 +421,11 @@ - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { self.draggedOffStartDay = YES; } } + + if(!self.allowRangeSelect) { + self.draggingStartDay = touchedView.day; + self.selectedRange = [[DSLCalendarRange alloc] initWithStartDay:touchedView.day endDay:touchedView.day]; + } [self positionCalloutViewForDayView:touchedView]; } diff --git a/Example/DSLCalendarViewExample/ViewController.m b/Example/DSLCalendarViewExample/ViewController.m index 9b6487b..8913678 100644 --- a/Example/DSLCalendarViewExample/ViewController.m +++ b/Example/DSLCalendarViewExample/ViewController.m @@ -23,6 +23,7 @@ - (void)viewDidLoad // Do any additional setup after loading the view, typically from a nib. self.calendarView.delegate = self; + self.calendarView.allowRangeSelect = YES; } - (void)viewDidUnload