diff --git a/Example-Objc/FSCalendar.xcodeproj/project.pbxproj b/Example-Objc/FSCalendar.xcodeproj/project.pbxproj index 8d13c9b0..e0bf6ebd 100644 --- a/Example-Objc/FSCalendar.xcodeproj/project.pbxproj +++ b/Example-Objc/FSCalendar.xcodeproj/project.pbxproj @@ -755,7 +755,7 @@ CLANG_ANALYZER_NONNULL = YES; DEBUG_INFORMATION_FORMAT = dwarf; INFOPLIST_FILE = FSCalendarTests/Info.plist; - IPHONEOS_DEPLOYMENT_TARGET = 9.3; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.wenchao.FSCalendarTests; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -769,7 +769,7 @@ BUNDLE_LOADER = "$(TEST_HOST)"; CLANG_ANALYZER_NONNULL = YES; INFOPLIST_FILE = FSCalendarTests/Info.plist; - IPHONEOS_DEPLOYMENT_TARGET = 9.3; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.wenchao.FSCalendarTests; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -825,7 +825,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 8.0; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; @@ -873,7 +873,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 8.0; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; VALIDATE_PRODUCT = YES; @@ -886,7 +886,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; DEVELOPMENT_TEAM = HZF422TY46; INFOPLIST_FILE = "$(SRCROOT)/Info.plist"; - IPHONEOS_DEPLOYMENT_TARGET = 9.0; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.wenchaod.FSCalendarExample; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -900,7 +900,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; DEVELOPMENT_TEAM = HZF422TY46; INFOPLIST_FILE = "$(SRCROOT)/Info.plist"; - IPHONEOS_DEPLOYMENT_TARGET = 9.0; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.wenchaod.FSCalendarExample; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -923,7 +923,7 @@ ); INFOPLIST_FILE = "$(SRCROOT)/../FSCalendar/Info.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - IPHONEOS_DEPLOYMENT_TARGET = 9.0; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; MARKETING_VERSION = 2.8.4; PRODUCT_BUNDLE_IDENTIFIER = com.wenchaod.FSCalendar; @@ -946,7 +946,7 @@ DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = "$(SRCROOT)/../FSCalendar/Info.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - IPHONEOS_DEPLOYMENT_TARGET = 9.0; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; MARKETING_VERSION = 2.8.4; PRODUCT_BUNDLE_IDENTIFIER = com.wenchaod.FSCalendar; @@ -970,7 +970,7 @@ "$(inherited)", ); INFOPLIST_FILE = FSCalendarExampleUITests/Info.plist; - IPHONEOS_DEPLOYMENT_TARGET = 10.2; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.wenchaod.FSCalendarExampleUITests; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -985,7 +985,7 @@ CLANG_WARN_DOCUMENTATION_COMMENTS = YES; DEVELOPMENT_TEAM = HZF422TY46; INFOPLIST_FILE = FSCalendarExampleUITests/Info.plist; - IPHONEOS_DEPLOYMENT_TARGET = 10.2; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.wenchaod.FSCalendarExampleUITests; PRODUCT_NAME = "$(TARGET_NAME)"; diff --git a/Example-Objc/RangePickerViewController.m b/Example-Objc/RangePickerViewController.m index af5e4479..02374263 100644 --- a/Example-Objc/RangePickerViewController.m +++ b/Example-Objc/RangePickerViewController.m @@ -26,6 +26,9 @@ @interface RangePickerViewController () 0); @@ -234,6 +271,28 @@ - (NSInteger)numberOfRowsInMonth:(NSDate *)month return rowCount.integerValue; } +/** + 是否属于同一月 + + @param time1 time1 + @param time2 time2 + @return 同一月为真,否则为假 + */ +- (BOOL)isInSameMonth:(NSDate *)time1 time2:(NSDate *)time2 +{ + NSDate *date1 = time1; + NSDate *date2 = time2; + + NSCalendar *calendar = [NSCalendar currentCalendar]; + int unit = NSCalendarUnitMonth | NSCalendarUnitYear; + + NSDateComponents *nowCmps = [calendar components:unit fromDate:date1]; + NSDateComponents *selfCmps = [calendar components:unit fromDate:date2]; + + return (nowCmps.year == selfCmps.year)&&(nowCmps.month == selfCmps.month); +} + + - (NSInteger)numberOfRowsInSection:(NSInteger)section { if (self.calendar.transitionCoordinator.representingScope == FSCalendarScopeWeek) return 1; @@ -270,7 +329,7 @@ - (FSCalendarCoordinate)coordinateForIndexPath:(NSIndexPath *)indexPath - (void)reloadSections { - self.numberOfMonths = [self.gregorian components:NSCalendarUnitMonth fromDate:[self.gregorian fs_firstDayOfMonth:self.minimumDate] toDate:self.maximumDate options:0].month+1; + self.numberOfMonths = [self.gregorian components:NSCalendarUnitMonth fromDate:[self currentMiniDate] toDate:self.maximumDate options:0].month+1; self.numberOfWeeks = [self.gregorian components:NSCalendarUnitWeekOfYear fromDate:[self.gregorian fs_firstDayOfWeek:self.minimumDate] toDate:self.maximumDate options:0].weekOfYear+1; [self clearCaches]; } diff --git a/FSCalendar/FSCalendarCollectionViewLayout.m b/FSCalendar/FSCalendarCollectionViewLayout.m index 914b8983..8b2435d1 100644 --- a/FSCalendar/FSCalendarCollectionViewLayout.m +++ b/FSCalendar/FSCalendarCollectionViewLayout.m @@ -34,12 +34,16 @@ @interface FSCalendarCollectionViewLayout () @property (assign, nonatomic) CGSize contentSize; @property (assign, nonatomic) CGSize collectionViewSize; @property (assign, nonatomic) CGSize headerReferenceSize; +@property (assign, nonatomic) CGSize footerReferenceSize; + @property (assign, nonatomic) NSInteger numberOfSections; @property (assign, nonatomic) FSCalendarSeparators separators; @property (strong, nonatomic) NSMutableDictionary *itemAttributes; @property (strong, nonatomic) NSMutableDictionary *headerAttributes; +@property (strong, nonatomic) NSMutableDictionary *footerAttributes; + @property (strong, nonatomic) NSMutableDictionary *rowSeparatorAttributes; - (void)didReceiveNotifications:(NSNotification *)notification; @@ -69,6 +73,7 @@ - (instancetype)init self.itemAttributes = NSMutableDictionary.dictionary; self.headerAttributes = NSMutableDictionary.dictionary; + self.footerAttributes = NSMutableDictionary.dictionary; self.rowSeparatorAttributes = NSMutableDictionary.dictionary; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didReceiveNotifications:) name:UIDeviceOrientationDidChangeNotification object:nil]; @@ -105,6 +110,7 @@ - (void)prepareLayout [self.itemAttributes removeAllObjects]; [self.headerAttributes removeAllObjects]; + [self.footerAttributes removeAllObjects]; [self.rowSeparatorAttributes removeAllObjects]; self.headerReferenceSize = ({ @@ -115,6 +121,14 @@ - (void)prepareLayout } headerSize; }); + self.footerReferenceSize = ({ + CGSize headerSize = CGSizeZero; + if (self.calendar.floatingMode) { + CGFloat headerHeight = self.calendar.footerHeight; + headerSize = CGSizeMake(self.collectionView.fs_width, headerHeight); + } + headerSize; + }); self.estimatedItemSize = ({ CGFloat width = (self.collectionView.fs_width-self.sectionInsets.left-self.sectionInsets.right)/7.0; CGFloat height = ({ @@ -227,6 +241,7 @@ - (void)prepareLayout for (int j = 0; j < rowCount; j++) { sectionHeight += self.heights[j]; } + sectionHeight += self.footerReferenceSize.height; self.sectionHeights[i] = sectionHeight; height += sectionHeight; } @@ -394,6 +409,8 @@ - (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect } } } + UICollectionViewLayoutAttributes *footerAttributes = [self layoutAttributesForSupplementaryViewOfKind:UICollectionElementKindSectionFooter atIndexPath:[NSIndexPath indexPathForItem:0 inSection:section]]; + [layoutAttributes addObject:footerAttributes]; } } @@ -456,6 +473,16 @@ - (UICollectionViewLayoutAttributes *)layoutAttributesForSupplementaryViewOfKind } return attributes; } + + if ([elementKind isEqualToString:UICollectionElementKindSectionFooter]) { + UICollectionViewLayoutAttributes *attributes = self.footerAttributes[indexPath]; + if (!attributes) { + attributes = [UICollectionViewLayoutAttributes layoutAttributesForSupplementaryViewOfKind:UICollectionElementKindSectionFooter withIndexPath:indexPath]; + attributes.frame = CGRectMake(0, self.sectionBottoms[indexPath.section]-self.footerReferenceSize.height, self.collectionView.fs_width, self.footerReferenceSize.height); + self.footerAttributes[indexPath] = attributes; + } + return attributes; + } return nil; } @@ -517,6 +544,7 @@ - (void)didReceiveNotifications:(NSNotification *)notification if ([notification.name isEqualToString:UIApplicationDidReceiveMemoryWarningNotification]) { [self.itemAttributes removeAllObjects]; [self.headerAttributes removeAllObjects]; + [self.footerAttributes removeAllObjects]; [self.rowSeparatorAttributes removeAllObjects]; } } diff --git a/FSCalendar/FSCalendarExtensions.h b/FSCalendar/FSCalendarExtensions.h index 4b066b4b..2c00defe 100644 --- a/FSCalendar/FSCalendarExtensions.h +++ b/FSCalendar/FSCalendarExtensions.h @@ -45,7 +45,7 @@ NS_ASSUME_NONNULL_BEGIN - (nullable NSDate *)fs_lastDayOfWeek:(NSDate *)week; - (nullable NSDate *)fs_middleDayOfWeek:(NSDate *)week; - (NSInteger)fs_numberOfDaysInMonth:(NSDate *)month; - +- (NSInteger)fs_numberOfDaysInMonth:(NSDate *)month currentDay:(NSDate *)currentDate isRest:(BOOL)isRest; @end @interface NSMapTable (FSCalendarExtensions) diff --git a/FSCalendar/FSCalendarExtensions.m b/FSCalendar/FSCalendarExtensions.m index d955c4c9..024a7a6e 100644 --- a/FSCalendar/FSCalendarExtensions.m +++ b/FSCalendar/FSCalendarExtensions.m @@ -216,6 +216,29 @@ - (NSInteger)fs_numberOfDaysInMonth:(NSDate *)month return days.length; } + +- (NSInteger)fs_numberOfDaysInMonth:(NSDate *)month currentDay:(NSDate *)currentDate isRest:(BOOL)isRest +{ + NSInteger allDays; + if(isRest){ + if (!month) return 0; + NSRange days = [self rangeOfUnit:NSCalendarUnitDay + inUnit:NSCalendarUnitMonth + forDate:month]; + + // 计算当月当前天数 + NSDateComponents *currentDateComponents = [self components:NSCalendarUnitDay fromDate:currentDate]; + NSInteger currentDay = [currentDateComponents day]; + allDays = days.length - currentDay + 1; + }else { + // 计算当月当前天数 + NSDateComponents *currentDateComponents = [self components:NSCalendarUnitDay fromDate:currentDate]; + NSInteger currentDay = [currentDateComponents day]; + allDays = currentDay; + } + return allDays; +} + - (NSDateComponents *)fs_privateComponents { NSDateComponents *components = objc_getAssociatedObject(self, _cmd);