diff --git a/FSCalendar.podspec b/FSCalendar.podspec index 21dd4bf0..e680d56c 100644 --- a/FSCalendar.podspec +++ b/FSCalendar.podspec @@ -1,7 +1,7 @@ Pod::Spec.new do |s| s.name = "FSCalendar" - s.version = "2.3.1" + s.version = "2.3.2.beta" s.summary = "A superiorly awesome iOS7+ calendar control, compatible with both Objective-C and Swift2." s.homepage = "https://github.com/WenchaoD/FSCalendar" diff --git a/FSCalendar/FSCalendar+DateTools.m b/FSCalendar/FSCalendar+DateTools.m index 537439e3..bf7fe0dd 100644 --- a/FSCalendar/FSCalendar+DateTools.m +++ b/FSCalendar/FSCalendar+DateTools.m @@ -289,7 +289,7 @@ - (BOOL)isDate:(NSDate *)date1 equalToDate:(NSDate *)date2 toCalendarUnit:(FSCal - (BOOL)isDateInToday:(NSDate *)date { - return [self isDate:date equalToDate:self.today toCalendarUnit:FSCalendarUnitDay]; + return [self isDate:date equalToDate:[NSDate date] toCalendarUnit:FSCalendarUnitDay]; } - (NSString *)stringFromDate:(NSDate *)date format:(NSString *)format diff --git a/FSCalendar/FSCalendar.h b/FSCalendar/FSCalendar.h index 86acc001..a2689686 100644 --- a/FSCalendar/FSCalendar.h +++ b/FSCalendar/FSCalendar.h @@ -260,9 +260,9 @@ IB_DESIGNABLE @property (weak, nonatomic) IBOutlet id dataSource; /** - * A special mark will be put on today of the calendar + * A special mark will be put on 'today' of the calendar. */ -@property (strong, nonatomic) NSDate *today; +@property (nullable, strong, nonatomic) NSDate *today; /** * The current page of calendar diff --git a/FSCalendar/FSCalendar.m b/FSCalendar/FSCalendar.m index 0bd3e550..b138ba27 100644 --- a/FSCalendar/FSCalendar.m +++ b/FSCalendar/FSCalendar.m @@ -787,31 +787,34 @@ - (void)setFirstWeekday:(NSUInteger)firstWeekday - (void)setToday:(NSDate *)today { [self requestBoundingDatesIfNecessary]; - if ([self daysFromDate:_minimumDate toDate:today] < 0) { - today = _minimumDate.copy; - } else if ([self daysFromDate:_maximumDate toDate:today] > 0) { - today = _maximumDate.copy; - } - if (![self isDateInToday:today]) { - _today = [self dateByIgnoringTimeComponentsOfDate:today]; - switch (_scope) { - case FSCalendarScopeMonth: { - _currentPage = [self beginingOfMonthOfDate:today]; - break; - } - case FSCalendarScopeWeek: { - _currentPage = [self beginingOfWeekOfDate:today]; - break; + if (!today) { + _today = nil; + } else { + if ([self daysFromDate:_minimumDate toDate:today] < 0) { + today = _minimumDate.copy; + } else if ([self daysFromDate:_maximumDate toDate:today] > 0) { + today = _maximumDate.copy; + } + if (![self isDateInToday:today]) { + _today = [self dateByIgnoringTimeComponentsOfDate:today]; + switch (_scope) { + case FSCalendarScopeMonth: { + _currentPage = [self beginingOfMonthOfDate:today]; + break; + } + case FSCalendarScopeWeek: { + _currentPage = [self beginingOfWeekOfDate:today]; + break; + } } + _needsAdjustingMonthPosition = YES; + [self setNeedsLayout]; } - _needsAdjustingMonthPosition = YES; - [self setNeedsLayout]; - - [_collectionView.visibleCells makeObjectsPerformSelector:@selector(setDateIsToday:) withObject:@NO]; - [[_collectionView cellForItemAtIndexPath:[self indexPathForDate:today]] setValue:@YES forKey:@"dateIsToday"]; - [_collectionView.visibleCells makeObjectsPerformSelector:@selector(setNeedsLayout)]; - } + + [_collectionView.visibleCells makeObjectsPerformSelector:@selector(setDateIsToday:) withObject:@NO]; + [[_collectionView cellForItemAtIndexPath:[self indexPathForDate:today]] setValue:@YES forKey:@"dateIsToday"]; + [_collectionView.visibleCells makeObjectsPerformSelector:@selector(setNeedsLayout)]; } - (void)setCurrentPage:(NSDate *)currentPage @@ -1342,6 +1345,7 @@ - (void)scrollToPageForDate:(NSDate *)date animated:(BOOL)animated - (NSDate *)dateForIndexPath:(NSIndexPath *)indexPath scope:(FSCalendarScope)scope { + if (!indexPath) return nil; switch (scope) { case FSCalendarScopeMonth: { NSDate *currentPage = [self dateByAddingMonths:indexPath.section toDate:[self beginingOfMonthOfDate:_minimumDate]]; @@ -1379,6 +1383,7 @@ - (NSDate *)dateForIndexPath:(NSIndexPath *)indexPath - (NSIndexPath *)indexPathForDate:(NSDate *)date scope:(FSCalendarScope)scope { + if (!date) return nil; NSInteger item = 0; NSInteger section = 0; switch (scope) { @@ -1611,7 +1616,7 @@ - (void)reloadDataForCell:(FSCalendarCell *)cell atIndexPath:(NSIndexPath *)inde cell.title = [self titleForDate:cell.date]; cell.subtitle = [self subtitleForDate:cell.date]; cell.dateIsSelected = [_selectedDates containsObject:cell.date]; - cell.dateIsToday = [self isDateInToday:cell.date]; + cell.dateIsToday = self.today? [self isDateInToday:cell.date] : NO; switch (_scope) { case FSCalendarScopeMonth: { NSDate *firstPage = [self beginingOfMonthOfDate:_minimumDate]; diff --git a/FSCalendar/Info.plist b/FSCalendar/Info.plist index a5d169ce..60f7e2b9 100644 --- a/FSCalendar/Info.plist +++ b/FSCalendar/Info.plist @@ -15,7 +15,7 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 2.3.1 + 2.3.2.beta CFBundleSignature ???? CFBundleVersion