From ae203f8a17fdcf9cea7bd1bb3d3049a7e75d276a Mon Sep 17 00:00:00 2001 From: Wenchao Ding Date: Sat, 22 Oct 2016 19:46:27 +0800 Subject: [PATCH 1/5] calendar.appearance.weekdayBackground --- .../project.pbxproj | 14 +- Example/Base.lproj/Main_iPad.storyboard | 3 +- Example/Base.lproj/Main_iPhone.storyboard | 2 +- Example/FSCalendar.xcodeproj/project.pbxproj | 24 +--- Example/StoryboardExampleViewController.m | 1 + FSCalendar/FSCalendar+IBExtension.h | 65 --------- FSCalendar/FSCalendar+IBExtension.m | 31 ----- FSCalendar/FSCalendar.h | 50 ++++++- FSCalendar/FSCalendar.m | 65 +++++++-- FSCalendar/FSCalendarAppearance.h | 7 +- FSCalendar/FSCalendarAppearance.m | 37 +++-- FSCalendar/FSCalendarCell.h | 12 +- FSCalendar/FSCalendarCell.m | 115 ++++++++++++++++ FSCalendar/FSCalendarCollectionView.m | 9 ++ FSCalendar/FSCalendarDynamicHeader.h | 3 +- FSCalendar/FSCalendarEventIndicator.h | 17 --- FSCalendar/FSCalendarEventIndicator.m | 126 ------------------ FSCalendar/FSCalendarFlowLayout.m | 1 - FSCalendar/FSCalendarStickyHeader.h | 5 +- FSCalendar/FSCalendarStickyHeader.m | 31 ++++- .../SwiftExample.xcodeproj/project.pbxproj | 12 -- .../project.pbxproj | 12 -- 22 files changed, 297 insertions(+), 345 deletions(-) delete mode 100644 FSCalendar/FSCalendar+IBExtension.h delete mode 100644 FSCalendar/FSCalendar+IBExtension.m delete mode 100644 FSCalendar/FSCalendarEventIndicator.h delete mode 100644 FSCalendar/FSCalendarEventIndicator.m diff --git a/DynamicTodayExtensionExample/DynamicTodayExtensionExample.xcodeproj/project.pbxproj b/DynamicTodayExtensionExample/DynamicTodayExtensionExample.xcodeproj/project.pbxproj index 062659b6..a2cebaa4 100644 --- a/DynamicTodayExtensionExample/DynamicTodayExtensionExample.xcodeproj/project.pbxproj +++ b/DynamicTodayExtensionExample/DynamicTodayExtensionExample.xcodeproj/project.pbxproj @@ -19,13 +19,11 @@ 305233411D8170B20070AAFE /* DynamicTodayViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 305233401D8170B20070AAFE /* DynamicTodayViewController.m */; }; 305233431D8170C60070AAFE /* Image.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 305233421D8170C60070AAFE /* Image.xcassets */; }; 305233671D8170E50070AAFE /* FSCalendar+Deprecated.m in Sources */ = {isa = PBXBuildFile; fileRef = 305233481D8170E50070AAFE /* FSCalendar+Deprecated.m */; }; - 305233681D8170E50070AAFE /* FSCalendar+IBExtension.m in Sources */ = {isa = PBXBuildFile; fileRef = 3052334A1D8170E50070AAFE /* FSCalendar+IBExtension.m */; }; 305233691D8170E50070AAFE /* FSCalendar.m in Sources */ = {isa = PBXBuildFile; fileRef = 3052334C1D8170E50070AAFE /* FSCalendar.m */; }; 3052336A1D8170E50070AAFE /* FSCalendarAnimator.m in Sources */ = {isa = PBXBuildFile; fileRef = 3052334E1D8170E50070AAFE /* FSCalendarAnimator.m */; }; 3052336B1D8170E50070AAFE /* FSCalendarAppearance.m in Sources */ = {isa = PBXBuildFile; fileRef = 305233501D8170E50070AAFE /* FSCalendarAppearance.m */; }; 3052336C1D8170E50070AAFE /* FSCalendarCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 305233521D8170E50070AAFE /* FSCalendarCell.m */; }; 3052336D1D8170E50070AAFE /* FSCalendarCollectionView.m in Sources */ = {isa = PBXBuildFile; fileRef = 305233541D8170E50070AAFE /* FSCalendarCollectionView.m */; }; - 3052336F1D8170E50070AAFE /* FSCalendarEventIndicator.m in Sources */ = {isa = PBXBuildFile; fileRef = 305233591D8170E50070AAFE /* FSCalendarEventIndicator.m */; }; 305233701D8170E50070AAFE /* FSCalendarFlowLayout.m in Sources */ = {isa = PBXBuildFile; fileRef = 3052335B1D8170E50070AAFE /* FSCalendarFlowLayout.m */; }; 305233711D8170E50070AAFE /* FSCalendarHeader.m in Sources */ = {isa = PBXBuildFile; fileRef = 3052335D1D8170E50070AAFE /* FSCalendarHeader.m */; }; 305233721D8170E50070AAFE /* FSCalendarScopeHandle.m in Sources */ = {isa = PBXBuildFile; fileRef = 3052335F1D8170E50070AAFE /* FSCalendarScopeHandle.m */; }; @@ -78,8 +76,6 @@ 305233401D8170B20070AAFE /* DynamicTodayViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DynamicTodayViewController.m; sourceTree = ""; }; 305233421D8170C60070AAFE /* Image.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Image.xcassets; sourceTree = ""; }; 305233481D8170E50070AAFE /* FSCalendar+Deprecated.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "FSCalendar+Deprecated.m"; sourceTree = ""; }; - 305233491D8170E50070AAFE /* FSCalendar+IBExtension.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "FSCalendar+IBExtension.h"; sourceTree = ""; }; - 3052334A1D8170E50070AAFE /* FSCalendar+IBExtension.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "FSCalendar+IBExtension.m"; sourceTree = ""; }; 3052334B1D8170E50070AAFE /* FSCalendar.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FSCalendar.h; sourceTree = ""; }; 3052334C1D8170E50070AAFE /* FSCalendar.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FSCalendar.m; sourceTree = ""; }; 3052334D1D8170E50070AAFE /* FSCalendarAnimator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FSCalendarAnimator.h; sourceTree = ""; }; @@ -91,8 +87,6 @@ 305233531D8170E50070AAFE /* FSCalendarCollectionView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FSCalendarCollectionView.h; sourceTree = ""; }; 305233541D8170E50070AAFE /* FSCalendarCollectionView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FSCalendarCollectionView.m; sourceTree = ""; }; 305233571D8170E50070AAFE /* FSCalendarDynamicHeader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FSCalendarDynamicHeader.h; sourceTree = ""; }; - 305233581D8170E50070AAFE /* FSCalendarEventIndicator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FSCalendarEventIndicator.h; sourceTree = ""; }; - 305233591D8170E50070AAFE /* FSCalendarEventIndicator.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FSCalendarEventIndicator.m; sourceTree = ""; }; 3052335A1D8170E50070AAFE /* FSCalendarFlowLayout.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FSCalendarFlowLayout.h; sourceTree = ""; }; 3052335B1D8170E50070AAFE /* FSCalendarFlowLayout.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FSCalendarFlowLayout.m; sourceTree = ""; }; 3052335C1D8170E50070AAFE /* FSCalendarHeader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FSCalendarHeader.h; sourceTree = ""; }; @@ -206,9 +200,6 @@ 305233541D8170E50070AAFE /* FSCalendarCollectionView.m */, 30A33A091DB1CA640039BEA3 /* FSCalendarConstants.h */, 30A33A0A1DB1CA640039BEA3 /* FSCalendarConstants.m */, - 305233571D8170E50070AAFE /* FSCalendarDynamicHeader.h */, - 305233581D8170E50070AAFE /* FSCalendarEventIndicator.h */, - 305233591D8170E50070AAFE /* FSCalendarEventIndicator.m */, 3052335A1D8170E50070AAFE /* FSCalendarFlowLayout.h */, 3052335B1D8170E50070AAFE /* FSCalendarFlowLayout.m */, 3052335C1D8170E50070AAFE /* FSCalendarHeader.h */, @@ -219,9 +210,8 @@ 305233611D8170E50070AAFE /* FSCalendarStickyHeader.m */, 3055B1C91DA933AD002AFA13 /* FSCalendarExtensions.h */, 3055B1CA1DA933AD002AFA13 /* FSCalendarExtensions.m */, + 305233571D8170E50070AAFE /* FSCalendarDynamicHeader.h */, 305233481D8170E50070AAFE /* FSCalendar+Deprecated.m */, - 305233491D8170E50070AAFE /* FSCalendar+IBExtension.h */, - 3052334A1D8170E50070AAFE /* FSCalendar+IBExtension.m */, 305233621D8170E50070AAFE /* Info.plist */, ); name = FSCalendar; @@ -342,7 +332,6 @@ buildActionMask = 2147483647; files = ( 30A33A0B1DB1CA640039BEA3 /* FSCalendarConstants.m in Sources */, - 305233681D8170E50070AAFE /* FSCalendar+IBExtension.m in Sources */, 305233721D8170E50070AAFE /* FSCalendarScopeHandle.m in Sources */, 305233691D8170E50070AAFE /* FSCalendar.m in Sources */, 305233671D8170E50070AAFE /* FSCalendar+Deprecated.m in Sources */, @@ -351,7 +340,6 @@ 305233711D8170E50070AAFE /* FSCalendarHeader.m in Sources */, 305233701D8170E50070AAFE /* FSCalendarFlowLayout.m in Sources */, 3055B1CB1DA933AD002AFA13 /* FSCalendarExtensions.m in Sources */, - 3052336F1D8170E50070AAFE /* FSCalendarEventIndicator.m in Sources */, 3052336C1D8170E50070AAFE /* FSCalendarCell.m in Sources */, 3052336D1D8170E50070AAFE /* FSCalendarCollectionView.m in Sources */, 305233411D8170B20070AAFE /* DynamicTodayViewController.m in Sources */, diff --git a/Example/Base.lproj/Main_iPad.storyboard b/Example/Base.lproj/Main_iPad.storyboard index 09bbc0ee..f9ea8f0a 100644 --- a/Example/Base.lproj/Main_iPad.storyboard +++ b/Example/Base.lproj/Main_iPad.storyboard @@ -1,5 +1,5 @@ - + @@ -293,7 +293,6 @@ - diff --git a/Example/Base.lproj/Main_iPhone.storyboard b/Example/Base.lproj/Main_iPhone.storyboard index 00b4133a..346c8500 100644 --- a/Example/Base.lproj/Main_iPhone.storyboard +++ b/Example/Base.lproj/Main_iPhone.storyboard @@ -1,5 +1,5 @@ - + diff --git a/Example/FSCalendar.xcodeproj/project.pbxproj b/Example/FSCalendar.xcodeproj/project.pbxproj index 29f40476..1d03ba0b 100644 --- a/Example/FSCalendar.xcodeproj/project.pbxproj +++ b/Example/FSCalendar.xcodeproj/project.pbxproj @@ -11,7 +11,7 @@ 30145EF11D6D754D00AA5F72 /* FSCalendarTests.m in Sources */ = {isa = PBXBuildFile; fileRef = EE638CF51B8A1F550006DD1A /* FSCalendarTests.m */; }; 301F93451D8802D90028BEC8 /* FSCalendarExtensionTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 301F93441D8802D90028BEC8 /* FSCalendarExtensionTest.m */; }; 3031F3EF1CDEDFC500C174D7 /* ScopeHandleViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 3031F3EE1CDEDFC500C174D7 /* ScopeHandleViewController.m */; }; - 3055B1C21DA9323A002AFA13 /* FSCalendarExtensions.h in Headers */ = {isa = PBXBuildFile; fileRef = 3055B1C01DA9323A002AFA13 /* FSCalendarExtensions.h */; }; + 3055B1C21DA9323A002AFA13 /* FSCalendarExtensions.h in Headers */ = {isa = PBXBuildFile; fileRef = 3055B1C01DA9323A002AFA13 /* FSCalendarExtensions.h */; settings = {ATTRIBUTES = (Private, ); }; }; 3055B1C31DA9323A002AFA13 /* FSCalendarExtensions.m in Sources */ = {isa = PBXBuildFile; fileRef = 3055B1C11DA9323A002AFA13 /* FSCalendarExtensions.m */; }; 3055B1C41DA9323A002AFA13 /* FSCalendarExtensions.m in Sources */ = {isa = PBXBuildFile; fileRef = 3055B1C11DA9323A002AFA13 /* FSCalendarExtensions.m */; }; 3055B1C51DA9323A002AFA13 /* FSCalendarExtensions.m in Sources */ = {isa = PBXBuildFile; fileRef = 3055B1C11DA9323A002AFA13 /* FSCalendarExtensions.m */; }; @@ -20,9 +20,6 @@ 3065CA981CD31B81006C218D /* FSCalendarScopeHandle.m in Sources */ = {isa = PBXBuildFile; fileRef = 3065CA951CD31B81006C218D /* FSCalendarScopeHandle.m */; }; 3065CAA81CD3506A006C218D /* FSCalendar+Deprecated.m in Sources */ = {isa = PBXBuildFile; fileRef = 3065CAA61CD3506A006C218D /* FSCalendar+Deprecated.m */; }; 3065CAA91CD3506A006C218D /* FSCalendar+Deprecated.m in Sources */ = {isa = PBXBuildFile; fileRef = 3065CAA61CD3506A006C218D /* FSCalendar+Deprecated.m */; }; - 307E05B91C61EC5C0052A9B4 /* FSCalendarEventIndicator.h in Headers */ = {isa = PBXBuildFile; fileRef = 307E05B71C61EC5C0052A9B4 /* FSCalendarEventIndicator.h */; settings = {ATTRIBUTES = (Private, ); }; }; - 307E05BA1C61EC5C0052A9B4 /* FSCalendarEventIndicator.m in Sources */ = {isa = PBXBuildFile; fileRef = 307E05B81C61EC5C0052A9B4 /* FSCalendarEventIndicator.m */; }; - 307E05BB1C61EC5C0052A9B4 /* FSCalendarEventIndicator.m in Sources */ = {isa = PBXBuildFile; fileRef = 307E05B81C61EC5C0052A9B4 /* FSCalendarEventIndicator.m */; }; 308B58D81CC08FFA004E812D /* ButtonsViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 308B58D71CC08FFA004E812D /* ButtonsViewController.m */; }; 3092253A1B905C4300123031 /* FSCalendarConstants.h in Headers */ = {isa = PBXBuildFile; fileRef = 309225381B905C4300123031 /* FSCalendarConstants.h */; settings = {ATTRIBUTES = (Public, ); }; }; 3092253B1B905C4300123031 /* FSCalendarConstants.m in Sources */ = {isa = PBXBuildFile; fileRef = 309225391B905C4300123031 /* FSCalendarConstants.m */; }; @@ -32,18 +29,15 @@ 309539911C38D66C00BD37AA /* FSCalendarFlowLayout.m in Sources */ = {isa = PBXBuildFile; fileRef = 3095398E1C38D66C00BD37AA /* FSCalendarFlowLayout.m */; }; 309A42011D992C4A004E86CB /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 309A42001D992C4A004E86CB /* Images.xcassets */; }; 30B0BA9B1B8D8BC9004B9476 /* FSCalendar.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = EE638CE21B8A1F550006DD1A /* FSCalendar.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; - 30B0BACF1B8D8E23004B9476 /* FSCalendar+IBExtension.m in Sources */ = {isa = PBXBuildFile; fileRef = 30B0BABE1B8D8E22004B9476 /* FSCalendar+IBExtension.m */; }; 30B0BAD01B8D8E23004B9476 /* FSCalendar.m in Sources */ = {isa = PBXBuildFile; fileRef = 30B0BAC01B8D8E22004B9476 /* FSCalendar.m */; }; 30B0BAD11B8D8E23004B9476 /* FSCalendarAppearance.m in Sources */ = {isa = PBXBuildFile; fileRef = 30B0BAC21B8D8E22004B9476 /* FSCalendarAppearance.m */; }; 30B0BAD21B8D8E23004B9476 /* FSCalendarCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 30B0BAC41B8D8E22004B9476 /* FSCalendarCell.m */; }; 30B0BAD31B8D8E23004B9476 /* FSCalendarHeader.m in Sources */ = {isa = PBXBuildFile; fileRef = 30B0BAC71B8D8E22004B9476 /* FSCalendarHeader.m */; }; 30B0BAD51B8D8E23004B9476 /* Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 30B0BACA1B8D8E22004B9476 /* Info.plist */; }; - 30B0BAF41B8D9AC1004B9476 /* FSCalendar+IBExtension.m in Sources */ = {isa = PBXBuildFile; fileRef = 30B0BABE1B8D8E22004B9476 /* FSCalendar+IBExtension.m */; }; 30B0BAF61B8D9AC1004B9476 /* FSCalendarAppearance.m in Sources */ = {isa = PBXBuildFile; fileRef = 30B0BAC21B8D8E22004B9476 /* FSCalendarAppearance.m */; }; 30B0BAF71B8D9AC1004B9476 /* FSCalendarCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 30B0BAC41B8D8E22004B9476 /* FSCalendarCell.m */; }; 30B0BAF81B8D9AC1004B9476 /* FSCalendarHeader.m in Sources */ = {isa = PBXBuildFile; fileRef = 30B0BAC71B8D8E22004B9476 /* FSCalendarHeader.m */; }; 30B0BAFC1B8D9AD4004B9476 /* FSCalendar.h in Headers */ = {isa = PBXBuildFile; fileRef = 30B0BABF1B8D8E22004B9476 /* FSCalendar.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 30B0BB001B8D9B6C004B9476 /* FSCalendar+IBExtension.h in Headers */ = {isa = PBXBuildFile; fileRef = 30B0BABD1B8D8E22004B9476 /* FSCalendar+IBExtension.h */; settings = {ATTRIBUTES = (Private, ); }; }; 30B0BB011B8D9B6C004B9476 /* FSCalendarAppearance.h in Headers */ = {isa = PBXBuildFile; fileRef = 30B0BAC11B8D8E22004B9476 /* FSCalendarAppearance.h */; settings = {ATTRIBUTES = (Public, ); }; }; 30B0BB021B8D9B6C004B9476 /* FSCalendarCell.h in Headers */ = {isa = PBXBuildFile; fileRef = 30B0BAC31B8D8E22004B9476 /* FSCalendarCell.h */; settings = {ATTRIBUTES = (Private, ); }; }; 30B0BB031B8D9B6D004B9476 /* FSCalendarDynamicHeader.h in Headers */ = {isa = PBXBuildFile; fileRef = 30B0BAC51B8D8E22004B9476 /* FSCalendarDynamicHeader.h */; settings = {ATTRIBUTES = (Private, ); }; }; @@ -115,8 +109,6 @@ 3065CA951CD31B81006C218D /* FSCalendarScopeHandle.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FSCalendarScopeHandle.m; sourceTree = ""; }; 3065CAA61CD3506A006C218D /* FSCalendar+Deprecated.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "FSCalendar+Deprecated.m"; sourceTree = ""; }; 30671DC71D6D574C00BCFC4E /* FSCalendarTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = FSCalendarTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; - 307E05B71C61EC5C0052A9B4 /* FSCalendarEventIndicator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FSCalendarEventIndicator.h; sourceTree = ""; }; - 307E05B81C61EC5C0052A9B4 /* FSCalendarEventIndicator.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FSCalendarEventIndicator.m; sourceTree = ""; }; 308B58D61CC08FFA004E812D /* ButtonsViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ButtonsViewController.h; sourceTree = SOURCE_ROOT; }; 308B58D71CC08FFA004E812D /* ButtonsViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ButtonsViewController.m; sourceTree = SOURCE_ROOT; }; 309225381B905C4300123031 /* FSCalendarConstants.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FSCalendarConstants.h; sourceTree = ""; }; @@ -124,8 +116,6 @@ 3095398D1C38D66C00BD37AA /* FSCalendarFlowLayout.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FSCalendarFlowLayout.h; sourceTree = ""; }; 3095398E1C38D66C00BD37AA /* FSCalendarFlowLayout.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FSCalendarFlowLayout.m; sourceTree = ""; }; 309A42001D992C4A004E86CB /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = SOURCE_ROOT; }; - 30B0BABD1B8D8E22004B9476 /* FSCalendar+IBExtension.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "FSCalendar+IBExtension.h"; sourceTree = ""; }; - 30B0BABE1B8D8E22004B9476 /* FSCalendar+IBExtension.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "FSCalendar+IBExtension.m"; sourceTree = ""; }; 30B0BABF1B8D8E22004B9476 /* FSCalendar.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FSCalendar.h; sourceTree = ""; }; 30B0BAC01B8D8E22004B9476 /* FSCalendar.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FSCalendar.m; sourceTree = ""; }; 30B0BAC11B8D8E22004B9476 /* FSCalendarAppearance.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FSCalendarAppearance.h; sourceTree = ""; }; @@ -235,8 +225,6 @@ 3065CA951CD31B81006C218D /* FSCalendarScopeHandle.m */, 30B0BAC31B8D8E22004B9476 /* FSCalendarCell.h */, 30B0BAC41B8D8E22004B9476 /* FSCalendarCell.m */, - 307E05B71C61EC5C0052A9B4 /* FSCalendarEventIndicator.h */, - 307E05B81C61EC5C0052A9B4 /* FSCalendarEventIndicator.m */, EEC9C0371BDC9E7000383A07 /* FSCalendarCollectionView.h */, EEC9C0381BDC9E7000383A07 /* FSCalendarCollectionView.m */, 30B0BAC61B8D8E22004B9476 /* FSCalendarHeader.h */, @@ -249,8 +237,6 @@ 30CEF8FF1C950C1F008EAFB1 /* FSCalendarAnimator.m */, 3055B1C01DA9323A002AFA13 /* FSCalendarExtensions.h */, 3055B1C11DA9323A002AFA13 /* FSCalendarExtensions.m */, - 30B0BABD1B8D8E22004B9476 /* FSCalendar+IBExtension.h */, - 30B0BABE1B8D8E22004B9476 /* FSCalendar+IBExtension.m */, 30B0BAC51B8D8E22004B9476 /* FSCalendarDynamicHeader.h */, 3065CAA61CD3506A006C218D /* FSCalendar+Deprecated.m */, 30B0BAF31B8D9A91004B9476 /* Supporting Files */, @@ -407,14 +393,12 @@ 30B0BB021B8D9B6C004B9476 /* FSCalendarCell.h in Headers */, 30B0BB041B8D9B6D004B9476 /* FSCalendarHeader.h in Headers */, EEC9C0391BDC9E7000383A07 /* FSCalendarCollectionView.h in Headers */, - 307E05B91C61EC5C0052A9B4 /* FSCalendarEventIndicator.h in Headers */, 30FCB3961BAAD112002B87AD /* FSCalendarStickyHeader.h in Headers */, 3065CA961CD31B81006C218D /* FSCalendarScopeHandle.h in Headers */, - 3055B1C21DA9323A002AFA13 /* FSCalendarExtensions.h in Headers */, 3095398F1C38D66C00BD37AA /* FSCalendarFlowLayout.h in Headers */, + 3055B1C21DA9323A002AFA13 /* FSCalendarExtensions.h in Headers */, 30CEF9001C950C1F008EAFB1 /* FSCalendarAnimator.h in Headers */, 30B0BB031B8D9B6D004B9476 /* FSCalendarDynamicHeader.h in Headers */, - 30B0BB001B8D9B6C004B9476 /* FSCalendar+IBExtension.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -566,7 +550,6 @@ files = ( EE638CCE1B89DBD80006DD1A /* StoryboardExampleViewController.m in Sources */, EECA10F81BA9C0E400945B83 /* FullScreenExampleViewController.m in Sources */, - 307E05BA1C61EC5C0052A9B4 /* FSCalendarEventIndicator.m in Sources */, EE638CC91B89DB940006DD1A /* CalendarConfigViewController.m in Sources */, 30B0BAD01B8D8E23004B9476 /* FSCalendar.m in Sources */, 3065CAA81CD3506A006C218D /* FSCalendar+Deprecated.m in Sources */, @@ -581,7 +564,6 @@ 308B58D81CC08FFA004E812D /* ButtonsViewController.m in Sources */, EE638CCB1B89DBAC0006DD1A /* main.m in Sources */, 30B0BAD11B8D8E23004B9476 /* FSCalendarAppearance.m in Sources */, - 30B0BACF1B8D8E23004B9476 /* FSCalendar+IBExtension.m in Sources */, 30CEF9011C950C1F008EAFB1 /* FSCalendarAnimator.m in Sources */, EEC9C03A1BDC9E7000383A07 /* FSCalendarCollectionView.m in Sources */, 30D55B101C90240000BB43D5 /* HidePlaceholderViewController.m in Sources */, @@ -599,8 +581,6 @@ buildActionMask = 2147483647; files = ( 30F5D8561B9FC33400C1C201 /* FSCalendar.m in Sources */, - 307E05BB1C61EC5C0052A9B4 /* FSCalendarEventIndicator.m in Sources */, - 30B0BAF41B8D9AC1004B9476 /* FSCalendar+IBExtension.m in Sources */, 30B0BAF61B8D9AC1004B9476 /* FSCalendarAppearance.m in Sources */, EEC9C03B1BDC9E7000383A07 /* FSCalendarCollectionView.m in Sources */, 3065CAA91CD3506A006C218D /* FSCalendar+Deprecated.m in Sources */, diff --git a/Example/StoryboardExampleViewController.m b/Example/StoryboardExampleViewController.m index 27de966a..6c78f5ac 100644 --- a/Example/StoryboardExampleViewController.m +++ b/Example/StoryboardExampleViewController.m @@ -66,6 +66,7 @@ - (void)viewDidLoad @"2015-10-15", @"2015-10-25"]; +// self.calendar.appearance.weekdayBackground = [UIColor cyanColor]; // _calendar.locale = [NSLocale currentLocale]; diff --git a/FSCalendar/FSCalendar+IBExtension.h b/FSCalendar/FSCalendar+IBExtension.h deleted file mode 100644 index b9166ec9..00000000 --- a/FSCalendar/FSCalendar+IBExtension.h +++ /dev/null @@ -1,65 +0,0 @@ -// -// FSCalendar+IBExtension.h -// FSCalendar -// -// Created by Wenchao Ding on 8/14/15. -// Copyright © 2016 Wenchao Ding. All rights reserved. -// -// 注意: 这些方法仅仅为了在IB中使用,不建议直接调用。这些方法在calendar.appearance中使用。如: calendar.appearance.eventDefaultColor -// Warning: For IB usage only. Directly calling these methods is NOT RECOMMENDED. Use calendar.appearance instead. - - -#import "FSCalendar.h" -#import "FSCalendarConstants.h" - -IB_DESIGNABLE -@interface FSCalendar (IBExtension) - -#if TARGET_INTERFACE_BUILDER - -@property (assign, nonatomic) IBInspectable BOOL adjustsFontSizeToFitContentSize; -@property (assign, nonatomic) IBInspectable CGFloat titleTextSize; -@property (assign, nonatomic) IBInspectable CGFloat subtitleTextSize; -@property (assign, nonatomic) IBInspectable CGFloat weekdayTextSize; -@property (assign, nonatomic) IBInspectable CGFloat headerTitleTextSize; - -@property (strong, nonatomic) IBInspectable UIColor *eventDefaultColor; -@property (strong, nonatomic) IBInspectable UIColor *eventSelectionColor; -@property (strong, nonatomic) IBInspectable UIColor *weekdayTextColor; - -@property (strong, nonatomic) IBInspectable UIColor *headerTitleColor; -@property (strong, nonatomic) IBInspectable NSString *headerDateFormat; -@property (assign, nonatomic) IBInspectable CGFloat headerMinimumDissolvedAlpha; - -@property (strong, nonatomic) IBInspectable UIColor *titleDefaultColor; -@property (strong, nonatomic) IBInspectable UIColor *titleSelectionColor; -@property (strong, nonatomic) IBInspectable UIColor *titleTodayColor; -@property (strong, nonatomic) IBInspectable UIColor *titlePlaceholderColor; -@property (strong, nonatomic) IBInspectable UIColor *titleWeekendColor; - -@property (strong, nonatomic) IBInspectable UIColor *subtitleDefaultColor; -@property (strong, nonatomic) IBInspectable UIColor *subtitleSelectionColor; -@property (strong, nonatomic) IBInspectable UIColor *subtitleTodayColor; -@property (strong, nonatomic) IBInspectable UIColor *subtitlePlaceholderColor; -@property (strong, nonatomic) IBInspectable UIColor *subtitleWeekendColor; - -@property (strong, nonatomic) IBInspectable UIColor *selectionColor; -@property (strong, nonatomic) IBInspectable UIColor *todayColor; -@property (strong, nonatomic) IBInspectable UIColor *todaySelectionColor; - -@property (strong, nonatomic) IBInspectable UIColor *borderDefaultColor; -@property (strong, nonatomic) IBInspectable UIColor *borderSelectionColor; - -@property (assign, nonatomic) IBInspectable CGFloat borderRadius; -@property (assign, nonatomic) IBInspectable BOOL useVeryShortWeekdaySymbols; - -@property (assign, nonatomic) IBInspectable BOOL fakeSubtitles; -@property (assign, nonatomic) IBInspectable BOOL fakeEventDots; -@property (assign, nonatomic) IBInspectable NSInteger fakedSelectedDay; - -#endif - -@end - - - diff --git a/FSCalendar/FSCalendar+IBExtension.m b/FSCalendar/FSCalendar+IBExtension.m deleted file mode 100644 index 54f99694..00000000 --- a/FSCalendar/FSCalendar+IBExtension.m +++ /dev/null @@ -1,31 +0,0 @@ -// -// FSCalendar+IBExtension.m -// FSCalendar -// -// Created by Wenchao Ding on 8/14/15. -// Copyright © 2016 Wenchao Ding. All rights reserved. -// - -#import "FSCalendar+IBExtension.h" - -@implementation FSCalendar (IBExtension) - -- (void)setValue:(id)value forUndefinedKey:(NSString *)key -{ -#if !TARGET_INTERFACE_BUILDER - if ([key hasPrefix:@"fake"]) { - return; - } -#endif - if (key.length) { - NSString *setter = [NSString stringWithFormat:@"set%@%@:",[key substringToIndex:1].uppercaseString,[key substringFromIndex:1]]; - if ([self.appearance respondsToSelector:NSSelectorFromString(setter)]) { - return [self.appearance setValue:value forKey:key]; - } - } - return [super setValue:value forUndefinedKey:key]; - -} - -@end - diff --git a/FSCalendar/FSCalendar.h b/FSCalendar/FSCalendar.h index 5b352e43..0d8704bc 100644 --- a/FSCalendar/FSCalendar.h +++ b/FSCalendar/FSCalendar.h @@ -229,7 +229,6 @@ NS_ASSUME_NONNULL_BEGIN /** * These functions are deprecated */ -- (FSCalendarCellStyle)calendar:(FSCalendar *)calendar appearance:(FSCalendarAppearance *)appearance cellStyleForDate:(NSDate *)date FSCalendarDeprecated(-calendar:appearance:cellShapeForDate:); - (nullable UIColor *)calendar:(FSCalendar *)calendar appearance:(FSCalendarAppearance *)appearance fillColorForDate:(NSDate *)date FSCalendarDeprecated(-calendar:appearance:fillDefaultColorForDate:); - (nullable UIColor *)calendar:(FSCalendar *)calendar appearance:(FSCalendarAppearance *)appearance selectionColorForDate:(NSDate *)date FSCalendarDeprecated(-calendar:appearance:fillSelectionColorForDate:); - (nullable UIColor *)calendar:(FSCalendar *)calendar appearance:(FSCalendarAppearance *)appearance eventColorForDate:(NSDate *)date FSCalendarDeprecated(-calendar:appearance:eventDefaultColorsForDate:); @@ -447,6 +446,55 @@ IB_DESIGNABLE @end +IB_DESIGNABLE +@interface FSCalendar (IBExtension) + +#if TARGET_INTERFACE_BUILDER + +@property (assign, nonatomic) IBInspectable BOOL adjustsFontSizeToFitContentSize; +@property (assign, nonatomic) IBInspectable CGFloat titleTextSize; +@property (assign, nonatomic) IBInspectable CGFloat subtitleTextSize; +@property (assign, nonatomic) IBInspectable CGFloat weekdayTextSize; +@property (assign, nonatomic) IBInspectable CGFloat headerTitleTextSize; + +@property (strong, nonatomic) IBInspectable UIColor *eventDefaultColor; +@property (strong, nonatomic) IBInspectable UIColor *eventSelectionColor; +@property (strong, nonatomic) IBInspectable UIColor *weekdayTextColor; + +@property (strong, nonatomic) IBInspectable UIColor *headerTitleColor; +@property (strong, nonatomic) IBInspectable NSString *headerDateFormat; +@property (assign, nonatomic) IBInspectable CGFloat headerMinimumDissolvedAlpha; + +@property (strong, nonatomic) IBInspectable UIColor *titleDefaultColor; +@property (strong, nonatomic) IBInspectable UIColor *titleSelectionColor; +@property (strong, nonatomic) IBInspectable UIColor *titleTodayColor; +@property (strong, nonatomic) IBInspectable UIColor *titlePlaceholderColor; +@property (strong, nonatomic) IBInspectable UIColor *titleWeekendColor; + +@property (strong, nonatomic) IBInspectable UIColor *subtitleDefaultColor; +@property (strong, nonatomic) IBInspectable UIColor *subtitleSelectionColor; +@property (strong, nonatomic) IBInspectable UIColor *subtitleTodayColor; +@property (strong, nonatomic) IBInspectable UIColor *subtitlePlaceholderColor; +@property (strong, nonatomic) IBInspectable UIColor *subtitleWeekendColor; + +@property (strong, nonatomic) IBInspectable UIColor *selectionColor; +@property (strong, nonatomic) IBInspectable UIColor *todayColor; +@property (strong, nonatomic) IBInspectable UIColor *todaySelectionColor; + +@property (strong, nonatomic) IBInspectable UIColor *borderDefaultColor; +@property (strong, nonatomic) IBInspectable UIColor *borderSelectionColor; + +@property (assign, nonatomic) IBInspectable CGFloat borderRadius; +@property (assign, nonatomic) IBInspectable BOOL useVeryShortWeekdaySymbols; + +@property (assign, nonatomic) IBInspectable BOOL fakeSubtitles; +@property (assign, nonatomic) IBInspectable BOOL fakeEventDots; +@property (assign, nonatomic) IBInspectable NSInteger fakedSelectedDay; + +#endif + +@end + #pragma mark - Deprecate diff --git a/FSCalendar/FSCalendar.m b/FSCalendar/FSCalendar.m index 9b75522c..801feaa0 100644 --- a/FSCalendar/FSCalendar.m +++ b/FSCalendar/FSCalendar.m @@ -91,7 +91,7 @@ @interface FSCalendar () { NSMutableArray *_selectedDates; } -@property (strong, nonatomic) NSMutableArray *weekdays; +@property (strong, nonatomic) NSArray *weekdays; @property (strong, nonatomic) NSMapTable *stickyHeaderMapTable; @property (strong, nonatomic) NSCalendar *gregorian; @@ -103,6 +103,7 @@ @interface FSCalendar () @property (weak , nonatomic) UIView *daysContainer; @property (weak , nonatomic) UIView *topBorder; @property (weak , nonatomic) UIView *bottomBorder; +@property (weak , nonatomic) UIImageView *weekdayView; @property (weak , nonatomic) FSCalendarScopeHandle *scopeHandle; @property (weak , nonatomic) FSCalendarCollectionView *collectionView; @property (weak , nonatomic) FSCalendarFlowLayout *collectionViewLayout; @@ -161,6 +162,7 @@ - (void)invalidateAppearanceForCell:(FSCalendarCell *)cell; - (void)invalidateWeekdayFont; - (void)invalidateWeekdayTextColor; +- (void)invalidateWeekdayBackground; - (void)invalidateViewFrames; @@ -282,12 +284,6 @@ - (void)initialize self.collectionView = collectionView; self.collectionViewLayout = collectionViewLayout; - - SEL selector = NSSelectorFromString(@"setPrefetchingEnabled:"); - if (selector && [collectionView respondsToSelector:selector]) { - [collectionView fs_performSelector:selector withObjects:@NO, nil]; - } - if (!FSCalendarInAppExtension) { UIView *view = [[UIView alloc] initWithFrame:CGRectZero]; @@ -347,6 +343,23 @@ - (void)setFrame:(CGRect)frame } } +- (void)setValue:(id)value forUndefinedKey:(NSString *)key +{ +#if !TARGET_INTERFACE_BUILDER + if ([key hasPrefix:@"fake"]) { + return; + } +#endif + if (key.length) { + NSString *setter = [NSString stringWithFormat:@"set%@%@:",[key substringToIndex:1].uppercaseString,[key substringFromIndex:1]]; + if ([self.appearance respondsToSelector:NSSelectorFromString(setter)]) { + return [self.appearance setValue:value forKey:key]; + } + } + return [super setValue:value forUndefinedKey:key]; + +} + - (void)layoutSubviews { [super layoutSubviews]; @@ -393,6 +406,9 @@ - (void)layoutSubviews weekdayWidth, weekdayHeight); }]; + if (_weekdayView) { + _weekdayView.frame = CGRectMake(_weekdays.firstObject.fs_left, _weekdays.firstObject.fs_top, _weekdays.lastObject.fs_right, _weekdays.firstObject.fs_height); + } _deliver.frame = CGRectMake(_header.fs_left, _header.fs_top, _header.fs_width, headerHeight+weekdayHeight); _deliver.hidden = _header.hidden; @@ -1526,7 +1542,7 @@ - (void)invalidateLayout if (!_weekdays.count) { NSArray *weekSymbols = self.gregorian.shortStandaloneWeekdaySymbols; - _weekdays = [NSMutableArray arrayWithCapacity:weekSymbols.count]; + NSMutableArray *weekdays = [NSMutableArray arrayWithCapacity:weekSymbols.count]; UIFont *weekdayFont = _appearance.preferredWeekdayFont; for (int i = 0; i < weekSymbols.count; i++) { UILabel *weekdayLabel = [[UILabel alloc] initWithFrame:CGRectZero]; @@ -1534,9 +1550,10 @@ - (void)invalidateLayout weekdayLabel.textAlignment = NSTextAlignmentCenter; weekdayLabel.font = weekdayFont; weekdayLabel.textColor = _appearance.weekdayTextColor; - [_weekdays addObject:weekdayLabel]; + [weekdays addObject:weekdayLabel]; [_contentView addSubview:weekdayLabel]; } + self.weekdays = weekdays; } if (self.showsScopeHandle) { @@ -1569,7 +1586,7 @@ - (void)invalidateLayout } if (_weekdays.count) { [_weekdays makeObjectsPerformSelector:@selector(removeFromSuperview)]; - [_weekdays removeAllObjects]; + _weekdays = @[]; } if (_scopeHandle) { @@ -1747,6 +1764,30 @@ - (void)invalidateWeekdayTextColor [_weekdays makeObjectsPerformSelector:@selector(setTextColor:) withObject:_appearance.weekdayTextColor]; } +- (void)invalidateWeekdayBackground +{ + if (self.appearance.weekdayBackground) { + if (!self.weekdayView) { + UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectZero]; + imageView.contentMode = UIViewContentModeCenter; + [self.contentView insertSubview:imageView belowSubview:self.weekdays.firstObject]; + self.weekdayView = imageView; + } + if (self.hasValidateVisibleLayout) { + self.weekdayView.frame = CGRectMake(self.weekdays.firstObject.fs_left, self.weekdays.firstObject.fs_top, self.weekdays.lastObject.fs_right, self.weekdays.firstObject.fs_height); + } + if ([self.appearance.weekdayBackground isKindOfClass:[UIImage class]]) { + self.weekdayView.image = self.appearance.weekdayBackground; + self.weekdayView.backgroundColor = nil; + } else { + self.weekdayView.image = nil; + self.weekdayView.backgroundColor = self.appearance.weekdayBackground; + } + } else { + self.weekdayView = nil; + } +} + - (void)invalidateViewFrames { _needsAdjustingViewFrame = YES; @@ -1981,10 +2022,6 @@ - (CGFloat)preferredBorderRadiusForDate:(NSDate *)date FSCalendarCellShape cellShape = [self.delegateAppearance calendar:self appearance:self.appearance cellShapeForDate:date]; return cellShape; } - else if (self.delegateAppearance && [self.delegateAppearance respondsToSelector:@selector(calendar:appearance:cellStyleForDate:)]) { - FSCalendarCellShape cellShape = (FSCalendarCellShape)[self.delegateAppearance calendar:self appearance:self.appearance cellStyleForDate:date]; - return cellShape; - } #pragma GCC diagnostic pop return -1; } diff --git a/FSCalendar/FSCalendarAppearance.h b/FSCalendar/FSCalendarAppearance.h index 9e4a1263..549dfaa2 100644 --- a/FSCalendar/FSCalendarAppearance.h +++ b/FSCalendar/FSCalendarAppearance.h @@ -101,6 +101,11 @@ typedef NS_OPTIONS(NSUInteger, FSCalendarCaseOptions) { */ @property (strong, nonatomic) UIColor *weekdayTextColor; +/** + * The background color/image for the weekdays + */ +@property (strong, nonatomic) id weekdayBackground; + /** * The color of month header text. */ @@ -234,9 +239,7 @@ typedef NS_OPTIONS(NSUInteger, FSCalendarCaseOptions) { */ @interface FSCalendarAppearance (Deprecated) -@property (assign, nonatomic) FSCalendarCellStyle cellStyle FSCalendarDeprecated('cellShape'); @property (assign, nonatomic) BOOL useVeryShortWeekdaySymbols FSCalendarDeprecated('caseOptions'); -@property (assign, nonatomic) BOOL autoAdjustTitleSize FSCalendarDeprecated('adjustFontSizeToFitContentSize'); @property (assign, nonatomic) BOOL adjustsFontSizeToFitCellSize FSCalendarDeprecated('adjustFontSizeToFitContentSize'); @property (assign, nonatomic) CGFloat titleTextSize FSCalendarDeprecated('titleFont'); @property (assign, nonatomic) CGFloat subtitleTextSize FSCalendarDeprecated('subtitleFont'); diff --git a/FSCalendar/FSCalendarAppearance.m b/FSCalendar/FSCalendarAppearance.m index e4625964..6d97b2ce 100644 --- a/FSCalendar/FSCalendarAppearance.m +++ b/FSCalendar/FSCalendarAppearance.m @@ -495,6 +495,17 @@ - (void)setWeekdayTextColor:(UIColor *)weekdayTextColor } } +- (void)setWeekdayBackground:(id)weekdayBackground +{ + if (weekdayBackground && (![weekdayBackground isKindOfClass:[UIImage class]] && ![weekdayBackground isKindOfClass:[UIColor class]])) { + [NSException raise:@"Invalidate Argument" format:@"The weekday background could only be a UIImage or UIColor instance"]; + } + if (![_weekdayBackground isEqual:weekdayBackground]) { + _weekdayBackground = weekdayBackground; + [self invalidateWeekdayBackground]; + } +} + - (void)setHeaderTitleColor:(UIColor *)color { if (![_headerTitleColor isEqual:color]) { @@ -667,6 +678,12 @@ - (void)invalidateWeekdayTextColor [_calendar.visibleStickyHeaders makeObjectsPerformSelector:_cmd]; } +- (void)invalidateWeekdayBackground +{ + [_calendar invalidateWeekdayBackground]; + [_calendar.visibleStickyHeaders makeObjectsPerformSelector:_cmd]; +} + - (void)invalidateHeaderFont { [_calendar.header.collectionView.visibleCells makeObjectsPerformSelector:_cmd]; @@ -684,16 +701,6 @@ - (void)invalidateHeaderTextColor @implementation FSCalendarAppearance (Deprecated) -- (void)setCellStyle:(FSCalendarCellStyle)cellStyle -{ - self.cellShape = (FSCalendarCellShape)cellStyle; -} - -- (FSCalendarCellStyle)cellStyle -{ - return (FSCalendarCellStyle)self.cellShape; -} - - (void)setUseVeryShortWeekdaySymbols:(BOOL)useVeryShortWeekdaySymbols { _caseOptions &= 15; @@ -705,16 +712,6 @@ - (BOOL)useVeryShortWeekdaySymbols return (_caseOptions & (15<<4) ) == FSCalendarCaseOptionsWeekdayUsesSingleUpperCase; } -- (void)setAutoAdjustTitleSize:(BOOL)autoAdjustTitleSize -{ - self.adjustsFontSizeToFitContentSize = autoAdjustTitleSize; -} - -- (BOOL)autoAdjustTitleSize -{ - return self.adjustsFontSizeToFitContentSize; -} - - (void)setTitleTextSize:(CGFloat)titleTextSize { self.titleFont = [UIFont fontWithName:_titleFontName size:titleTextSize]; diff --git a/FSCalendar/FSCalendarCell.h b/FSCalendar/FSCalendarCell.h index 1949d23a..6c114865 100644 --- a/FSCalendar/FSCalendarCell.h +++ b/FSCalendar/FSCalendarCell.h @@ -8,8 +8,8 @@ #import #import "FSCalendar.h" -#import "FSCalendarEventIndicator.h" +@class FSCalendarEventIndicator; @interface FSCalendarCell : UICollectionViewCell @property (weak, nonatomic) FSCalendar *calendar; @@ -70,3 +70,13 @@ - (void)performSelecting; @end + + +@interface FSCalendarEventIndicator : UIView + +@property (assign, nonatomic) NSInteger numberOfEvents; +@property (strong, nonatomic) id color; +@property (assign, nonatomic) BOOL needsAdjustingViewFrame; + +@end + diff --git a/FSCalendar/FSCalendarCell.m b/FSCalendar/FSCalendarCell.m index 4d93ccef..2bec89e7 100644 --- a/FSCalendar/FSCalendarCell.m +++ b/FSCalendar/FSCalendarCell.m @@ -462,4 +462,119 @@ - (void)setNeedsAdjustingViewFrame:(BOOL)needsAdjustingViewFrame @end +@interface FSCalendarEventIndicator () + +@property (weak, nonatomic) UIView *contentView; + +@property (strong, nonatomic) NSMutableArray *eventLayers; +@property (assign, nonatomic) BOOL needsInvalidatingColor; + +@end + +@implementation FSCalendarEventIndicator + +- (instancetype)initWithFrame:(CGRect)frame +{ + self = [super initWithFrame:frame]; + if (self) { + + UIView *view = [[UIView alloc] initWithFrame:CGRectZero]; + [self addSubview:view]; + self.contentView = view; + + self.eventLayers = [NSMutableArray arrayWithCapacity:3]; + for (int i = 0; i < 3; i++) { + CALayer *layer = [CALayer layer]; + layer.backgroundColor = [UIColor clearColor].CGColor; + [self.eventLayers addObject:layer]; + [self.contentView.layer addSublayer:layer]; + } + + _needsInvalidatingColor = YES; + _needsAdjustingViewFrame = YES; + + } + return self; +} + +- (void)layoutSubviews +{ + [super layoutSubviews]; + if (_needsAdjustingViewFrame) { + CGFloat diameter = MIN(MIN(self.fs_width, self.fs_height),FSCalendarMaximumEventDotDiameter); + self.contentView.fs_height = self.fs_height; + self.contentView.fs_width = (self.numberOfEvents*2-1)*diameter; + self.contentView.center = CGPointMake(CGRectGetMidX(self.bounds), CGRectGetMidY(self.bounds)); + } +} + +- (void)layoutSublayersOfLayer:(CALayer *)layer +{ + [super layoutSublayersOfLayer:layer]; + if (layer == self.layer) { + if (_needsAdjustingViewFrame) { + _needsAdjustingViewFrame = NO; + CGFloat diameter = MIN(MIN(self.fs_width, self.fs_height),FSCalendarMaximumEventDotDiameter); + for (int i = 0; i < self.eventLayers.count; i++) { + CALayer *eventLayer = self.eventLayers[i]; + eventLayer.hidden = i >= self.numberOfEvents; + if (!eventLayer.hidden) { + eventLayer.frame = CGRectMake(2*i*diameter, (self.fs_height-diameter)*0.5, diameter, diameter); + if (eventLayer.cornerRadius != diameter/2) { + eventLayer.cornerRadius = diameter/2; + } + } + } + } + if (_needsInvalidatingColor) { + _needsInvalidatingColor = NO; + if ([_color isKindOfClass:[UIColor class]]) { + [self.eventLayers makeObjectsPerformSelector:@selector(setBackgroundColor:) withObject:(id)[_color CGColor]]; + } else if ([_color isKindOfClass:[NSArray class]]) { + NSArray *colors = (NSArray *)_color; + if (colors.count) { + UIColor *lastColor = colors.firstObject; + for (int i = 0; i < self.eventLayers.count; i++) { + if (i < colors.count) { + lastColor = colors[i]; + } + CALayer *eventLayer = self.eventLayers[i]; + eventLayer.backgroundColor = lastColor.CGColor; + } + } + } + } + } +} + +- (void)setColor:(id)color +{ + if (![_color isEqual:color]) { + _color = color; + _needsInvalidatingColor = YES; + [self setNeedsLayout]; + } +} + +- (void)setNumberOfEvents:(NSInteger)numberOfEvents +{ + if (_numberOfEvents != numberOfEvents) { + _numberOfEvents = MIN(MAX(numberOfEvents,0),3); + _needsAdjustingViewFrame = YES; + [self setNeedsLayout]; + } +} + +- (void)setNeedsAdjustingViewFrame:(BOOL)needsAdjustingViewFrame +{ + if (_needsAdjustingViewFrame != needsAdjustingViewFrame) { + _needsAdjustingViewFrame = needsAdjustingViewFrame; + if (needsAdjustingViewFrame) { + [self setNeedsLayout]; + } + } +} + +@end + diff --git a/FSCalendar/FSCalendarCollectionView.m b/FSCalendar/FSCalendarCollectionView.m index 3abbde2a..bc31bbef 100644 --- a/FSCalendar/FSCalendarCollectionView.m +++ b/FSCalendar/FSCalendarCollectionView.m @@ -7,6 +7,7 @@ // #import "FSCalendarCollectionView.h" +#import "FSCalendarExtensions.h" @interface FSCalendarCollectionView () @@ -40,11 +41,19 @@ - (void)initialize { self.scrollsToTop = NO; self.contentInset = UIEdgeInsetsZero; + #ifdef __IPHONE_9_0 if ([self respondsToSelector:@selector(setSemanticContentAttribute:)]) { self.semanticContentAttribute = UISemanticContentAttributeForceLeftToRight; } #endif + +#ifdef __IPHONE_10_0 + SEL selector = NSSelectorFromString(@"setPrefetchingEnabled:"); + if (selector && [self respondsToSelector:selector]) { + [self fs_performSelector:selector withObjects:@NO, nil]; + } +#endif } - (void)setContentInset:(UIEdgeInsets)contentInset diff --git a/FSCalendar/FSCalendarDynamicHeader.h b/FSCalendar/FSCalendarDynamicHeader.h index 0e933bc9..56a685f9 100644 --- a/FSCalendar/FSCalendarDynamicHeader.h +++ b/FSCalendar/FSCalendarDynamicHeader.h @@ -28,7 +28,7 @@ @property (readonly, nonatomic) FSCalendarScopeHandle *scopeHandle; @property (readonly, nonatomic) FSCalendarFlowLayout *collectionViewLayout; @property (readonly, nonatomic) FSCalendarAnimator *animator; -@property (readonly, nonatomic) NSArray *weekdays; +@property (readonly, nonatomic) NSArray *weekdays; @property (readonly, nonatomic) BOOL floatingMode; @property (readonly, nonatomic) NSArray *visibleStickyHeaders; @property (readonly, nonatomic) CGFloat preferredHeaderHeight; @@ -49,6 +49,7 @@ - (void)invalidateWeekdayFont; - (void)invalidateWeekdayTextColor; +- (void)invalidateWeekdayBackground; - (void)invalidateHeaders; - (void)invalidateWeekdaySymbols; diff --git a/FSCalendar/FSCalendarEventIndicator.h b/FSCalendar/FSCalendarEventIndicator.h deleted file mode 100644 index 8e96a30c..00000000 --- a/FSCalendar/FSCalendarEventIndicator.h +++ /dev/null @@ -1,17 +0,0 @@ -// -// FSCalendarEventView.h -// FSCalendar -// -// Created by dingwenchao on 2/3/16. -// Copyright © 2016 wenchaoios. All rights reserved. -// - -#import - -@interface FSCalendarEventIndicator : UIView - -@property (assign, nonatomic) NSInteger numberOfEvents; -@property (strong, nonatomic) id color; -@property (assign, nonatomic) BOOL needsAdjustingViewFrame; - -@end diff --git a/FSCalendar/FSCalendarEventIndicator.m b/FSCalendar/FSCalendarEventIndicator.m deleted file mode 100644 index 55d491a6..00000000 --- a/FSCalendar/FSCalendarEventIndicator.m +++ /dev/null @@ -1,126 +0,0 @@ -// -// FSCalendarEventView.m -// FSCalendar -// -// Created by dingwenchao on 2/3/16. -// Copyright © 2016 wenchaoios. All rights reserved. -// - -#import "FSCalendarEventIndicator.h" -#import "FSCalendarConstants.h" -#import "FSCalendarExtensions.h" - -@interface FSCalendarEventIndicator () - -@property (weak, nonatomic) UIView *contentView; - -@property (strong, nonatomic) NSMutableArray *eventLayers; -@property (assign, nonatomic) BOOL needsInvalidatingColor; - -@end - -@implementation FSCalendarEventIndicator - -- (instancetype)initWithFrame:(CGRect)frame -{ - self = [super initWithFrame:frame]; - if (self) { - - UIView *view = [[UIView alloc] initWithFrame:CGRectZero]; - [self addSubview:view]; - self.contentView = view; - - self.eventLayers = [NSMutableArray arrayWithCapacity:3]; - for (int i = 0; i < 3; i++) { - CALayer *layer = [CALayer layer]; - layer.backgroundColor = [UIColor clearColor].CGColor; - [self.eventLayers addObject:layer]; - [self.contentView.layer addSublayer:layer]; - } - - _needsInvalidatingColor = YES; - _needsAdjustingViewFrame = YES; - - } - return self; -} - -- (void)layoutSubviews -{ - [super layoutSubviews]; - if (_needsAdjustingViewFrame) { - CGFloat diameter = MIN(MIN(self.fs_width, self.fs_height),FSCalendarMaximumEventDotDiameter); - self.contentView.fs_height = self.fs_height; - self.contentView.fs_width = (self.numberOfEvents*2-1)*diameter; - self.contentView.center = CGPointMake(CGRectGetMidX(self.bounds), CGRectGetMidY(self.bounds)); - } -} - -- (void)layoutSublayersOfLayer:(CALayer *)layer -{ - [super layoutSublayersOfLayer:layer]; - if (layer == self.layer) { - if (_needsAdjustingViewFrame) { - _needsAdjustingViewFrame = NO; - CGFloat diameter = MIN(MIN(self.fs_width, self.fs_height),FSCalendarMaximumEventDotDiameter); - for (int i = 0; i < self.eventLayers.count; i++) { - CALayer *eventLayer = self.eventLayers[i]; - eventLayer.hidden = i >= self.numberOfEvents; - if (!eventLayer.hidden) { - eventLayer.frame = CGRectMake(2*i*diameter, (self.fs_height-diameter)*0.5, diameter, diameter); - if (eventLayer.cornerRadius != diameter/2) { - eventLayer.cornerRadius = diameter/2; - } - } - } - } - if (_needsInvalidatingColor) { - _needsInvalidatingColor = NO; - if ([_color isKindOfClass:[UIColor class]]) { - [self.eventLayers makeObjectsPerformSelector:@selector(setBackgroundColor:) withObject:(id)[_color CGColor]]; - } else if ([_color isKindOfClass:[NSArray class]]) { - NSArray *colors = (NSArray *)_color; - if (colors.count) { - UIColor *lastColor = colors.firstObject; - for (int i = 0; i < self.eventLayers.count; i++) { - if (i < colors.count) { - lastColor = colors[i]; - } - CALayer *eventLayer = self.eventLayers[i]; - eventLayer.backgroundColor = lastColor.CGColor; - } - } - } - } - } -} - -- (void)setColor:(id)color -{ - if (![_color isEqual:color]) { - _color = color; - _needsInvalidatingColor = YES; - [self setNeedsLayout]; - } -} - -- (void)setNumberOfEvents:(NSInteger)numberOfEvents -{ - if (_numberOfEvents != numberOfEvents) { - _numberOfEvents = MIN(MAX(numberOfEvents,0),3); - _needsAdjustingViewFrame = YES; - [self setNeedsLayout]; - } -} - -- (void)setNeedsAdjustingViewFrame:(BOOL)needsAdjustingViewFrame -{ - if (_needsAdjustingViewFrame != needsAdjustingViewFrame) { - _needsAdjustingViewFrame = needsAdjustingViewFrame; - if (needsAdjustingViewFrame) { - [self setNeedsLayout]; - } - } -} - -@end diff --git a/FSCalendar/FSCalendarFlowLayout.m b/FSCalendar/FSCalendarFlowLayout.m index 9170be3e..cdfc085a 100644 --- a/FSCalendar/FSCalendarFlowLayout.m +++ b/FSCalendar/FSCalendarFlowLayout.m @@ -31,7 +31,6 @@ - (void)prepareLayout { [super prepareLayout]; - CGFloat rowHeight = self.calendar.preferredRowHeight; if (!self.calendar.floatingMode) { diff --git a/FSCalendar/FSCalendarStickyHeader.h b/FSCalendar/FSCalendarStickyHeader.h index 4a851ece..fbbf7f1f 100644 --- a/FSCalendar/FSCalendarStickyHeader.h +++ b/FSCalendar/FSCalendarStickyHeader.h @@ -17,14 +17,15 @@ @property (weak, nonatomic) UILabel *titleLabel; -@property (strong, nonatomic) NSArray *weekdayLabels; +@property (strong, nonatomic) NSArray *weekdayLabels; @property (strong, nonatomic) NSDate *month; - (void)invalidateHeaderFont; - (void)invalidateHeaderTextColor; - (void)invalidateWeekdayFont; - (void)invalidateWeekdayTextColor; +- (void)invalidateWeekdayBackground; - (void)invalidateWeekdaySymbols; -@end \ No newline at end of file +@end diff --git a/FSCalendar/FSCalendarStickyHeader.m b/FSCalendar/FSCalendarStickyHeader.m index 9b2dd952..6aeb71b9 100644 --- a/FSCalendar/FSCalendarStickyHeader.m +++ b/FSCalendar/FSCalendarStickyHeader.m @@ -14,8 +14,9 @@ @interface FSCalendarStickyHeader () -@property (weak, nonatomic) UIView *contentView; -@property (weak, nonatomic) UIView *separator; +@property (weak , nonatomic) UIView *contentView; +@property (weak , nonatomic) UIView *separator; +@property (weak , nonatomic) UIImageView *weekdayView; @property (assign, nonatomic) BOOL needsAdjustingViewFrame; @@ -84,6 +85,8 @@ - (void)layoutSubviews _separator.frame = CGRectMake(0, _contentView.fs_height-weekdayHeight-weekdayMargin*2, _contentView.fs_width, 1.0); _titleLabel.frame = CGRectMake(0, _separator.fs_bottom-titleHeight-weekdayMargin, titleWidth,titleHeight); + self.weekdayView.frame = CGRectMake(self.weekdayLabels.firstObject.fs_left, self.weekdayLabels.firstObject.fs_top, self.weekdayLabels.lastObject.fs_right, self.weekdayLabels.firstObject.fs_height); + } [self reloadData]; @@ -102,6 +105,7 @@ - (void)setCalendar:(FSCalendar *)calendar [self invalidateHeaderTextColor]; [self invalidateWeekdayFont]; [self invalidateWeekdayTextColor]; + [self invalidateWeekdayBackground]; } } @@ -151,6 +155,29 @@ - (void)invalidateWeekdaySymbols }]; } +- (void)invalidateWeekdayBackground +{ + if (self.appearance.weekdayBackground) { + if (!self.weekdayView) { + UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectZero]; + imageView.contentMode = UIViewContentModeCenter; + [self.contentView insertSubview:imageView belowSubview:self.weekdayLabels.firstObject]; + self.weekdayView = imageView; + } + + self.weekdayView.frame = CGRectMake(self.weekdayLabels.firstObject.fs_left, self.weekdayLabels.firstObject.fs_top, self.weekdayLabels.lastObject.fs_right, self.weekdayLabels.firstObject.fs_height); + + if ([self.appearance.weekdayBackground isKindOfClass:[UIImage class]]) { + self.weekdayView.image = self.appearance.weekdayBackground; + self.weekdayView.backgroundColor = nil; + } else { + self.weekdayView.image = nil; + self.weekdayView.backgroundColor = self.appearance.weekdayBackground; + } + } else { + self.weekdayView = nil; + } +} @end diff --git a/SwiftExample/SwiftExample.xcodeproj/project.pbxproj b/SwiftExample/SwiftExample.xcodeproj/project.pbxproj index 1f5b9dcd..053181fd 100644 --- a/SwiftExample/SwiftExample.xcodeproj/project.pbxproj +++ b/SwiftExample/SwiftExample.xcodeproj/project.pbxproj @@ -9,7 +9,6 @@ /* Begin PBXBuildFile section */ 300414221CD751B200453AEB /* FSCalendarScopeHandle.m in Sources */ = {isa = PBXBuildFile; fileRef = 300414211CD751B200453AEB /* FSCalendarScopeHandle.m */; }; 300414261CD751CF00453AEB /* FSCalendar+Deprecated.m in Sources */ = {isa = PBXBuildFile; fileRef = 300414241CD751CF00453AEB /* FSCalendar+Deprecated.m */; }; - 300BFB121C6446FA00399553 /* FSCalendarEventIndicator.m in Sources */ = {isa = PBXBuildFile; fileRef = 300BFB111C6446FA00399553 /* FSCalendarEventIndicator.m */; }; 303478391DB520C8007BBD2E /* TableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 303478381DB520C8007BBD2E /* TableViewController.swift */; }; 303DE6C11DB1CA3A00F43A0F /* FSCalendarConstants.m in Sources */ = {isa = PBXBuildFile; fileRef = 303DE6C01DB1CA3A00F43A0F /* FSCalendarConstants.m */; }; 3055B1C81DA9338C002AFA13 /* FSCalendarExtensions.m in Sources */ = {isa = PBXBuildFile; fileRef = 3055B1C71DA9338C002AFA13 /* FSCalendarExtensions.m */; }; @@ -22,7 +21,6 @@ EE0954B41B97DDE0007F6964 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = EE0954B31B97DDE0007F6964 /* Images.xcassets */; }; EE0954B71B97DDE0007F6964 /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = EE0954B51B97DDE0007F6964 /* LaunchScreen.xib */; }; EE0954C31B97DDE0007F6964 /* SwiftExampleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE0954C21B97DDE0007F6964 /* SwiftExampleTests.swift */; }; - EE0954E31B97DDF4007F6964 /* FSCalendar+IBExtension.m in Sources */ = {isa = PBXBuildFile; fileRef = EE0954CE1B97DDF4007F6964 /* FSCalendar+IBExtension.m */; }; EE0954E41B97DDF4007F6964 /* FSCalendar.m in Sources */ = {isa = PBXBuildFile; fileRef = EE0954D01B97DDF4007F6964 /* FSCalendar.m */; }; EE0954E51B97DDF4007F6964 /* FSCalendarAppearance.m in Sources */ = {isa = PBXBuildFile; fileRef = EE0954D21B97DDF4007F6964 /* FSCalendarAppearance.m */; }; EE0954E61B97DDF4007F6964 /* FSCalendarCell.m in Sources */ = {isa = PBXBuildFile; fileRef = EE0954D41B97DDF4007F6964 /* FSCalendarCell.m */; }; @@ -46,8 +44,6 @@ 300414201CD751B200453AEB /* FSCalendarScopeHandle.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FSCalendarScopeHandle.h; sourceTree = ""; }; 300414211CD751B200453AEB /* FSCalendarScopeHandle.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FSCalendarScopeHandle.m; sourceTree = ""; }; 300414241CD751CF00453AEB /* FSCalendar+Deprecated.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "FSCalendar+Deprecated.m"; sourceTree = ""; }; - 300BFB101C6446FA00399553 /* FSCalendarEventIndicator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FSCalendarEventIndicator.h; sourceTree = ""; }; - 300BFB111C6446FA00399553 /* FSCalendarEventIndicator.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FSCalendarEventIndicator.m; sourceTree = ""; }; 303478381DB520C8007BBD2E /* TableViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TableViewController.swift; sourceTree = ""; }; 303DE6BF1DB1CA3A00F43A0F /* FSCalendarConstants.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FSCalendarConstants.h; sourceTree = ""; }; 303DE6C01DB1CA3A00F43A0F /* FSCalendarConstants.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FSCalendarConstants.m; sourceTree = ""; }; @@ -66,8 +62,6 @@ EE0954BC1B97DDE0007F6964 /* SwiftExampleTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SwiftExampleTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; EE0954C11B97DDE0007F6964 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; EE0954C21B97DDE0007F6964 /* SwiftExampleTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwiftExampleTests.swift; sourceTree = ""; }; - EE0954CD1B97DDF4007F6964 /* FSCalendar+IBExtension.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "FSCalendar+IBExtension.h"; sourceTree = ""; }; - EE0954CE1B97DDF4007F6964 /* FSCalendar+IBExtension.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "FSCalendar+IBExtension.m"; sourceTree = ""; }; EE0954CF1B97DDF4007F6964 /* FSCalendar.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FSCalendar.h; sourceTree = ""; }; EE0954D01B97DDF4007F6964 /* FSCalendar.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FSCalendar.m; sourceTree = ""; }; EE0954D11B97DDF4007F6964 /* FSCalendarAppearance.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FSCalendarAppearance.h; sourceTree = ""; }; @@ -176,8 +170,6 @@ 300414211CD751B200453AEB /* FSCalendarScopeHandle.m */, EE0954D31B97DDF4007F6964 /* FSCalendarCell.h */, EE0954D41B97DDF4007F6964 /* FSCalendarCell.m */, - 300BFB101C6446FA00399553 /* FSCalendarEventIndicator.h */, - 300BFB111C6446FA00399553 /* FSCalendarEventIndicator.m */, 303DE6BF1DB1CA3A00F43A0F /* FSCalendarConstants.h */, 303DE6C01DB1CA3A00F43A0F /* FSCalendarConstants.m */, EEC9C03C1BDCA2D600383A07 /* FSCalendarCollectionView.h */, @@ -192,8 +184,6 @@ EE2B62821BB6D7FE00ACB430 /* FSCalendarStickyHeader.m */, 3055B1C61DA9338C002AFA13 /* FSCalendarExtensions.h */, 3055B1C71DA9338C002AFA13 /* FSCalendarExtensions.m */, - EE0954CD1B97DDF4007F6964 /* FSCalendar+IBExtension.h */, - EE0954CE1B97DDF4007F6964 /* FSCalendar+IBExtension.m */, 300414241CD751CF00453AEB /* FSCalendar+Deprecated.m */, EE0954D71B97DDF4007F6964 /* FSCalendarDynamicHeader.h */, EE0954DC1B97DDF4007F6964 /* Info.plist */, @@ -311,8 +301,6 @@ 303DE6C11DB1CA3A00F43A0F /* FSCalendarConstants.m in Sources */, EEC9C0401BDCA2D600383A07 /* FSCalendarCollectionView.m in Sources */, EE0954E81B97DDF4007F6964 /* FSCalendarHeader.m in Sources */, - EE0954E31B97DDF4007F6964 /* FSCalendar+IBExtension.m in Sources */, - 300BFB121C6446FA00399553 /* FSCalendarEventIndicator.m in Sources */, 303478391DB520C8007BBD2E /* TableViewController.swift in Sources */, EE2B62831BB6D7FE00ACB430 /* FSCalendarStickyHeader.m in Sources */, 306DB1461C96700800A10478 /* FSCalendarAnimator.m in Sources */, diff --git a/TodayExtensionExample/TodayExtensionExample.xcodeproj/project.pbxproj b/TodayExtensionExample/TodayExtensionExample.xcodeproj/project.pbxproj index 8a978731..7ed7f650 100644 --- a/TodayExtensionExample/TodayExtensionExample.xcodeproj/project.pbxproj +++ b/TodayExtensionExample/TodayExtensionExample.xcodeproj/project.pbxproj @@ -8,13 +8,11 @@ /* Begin PBXBuildFile section */ 300036ED1D9252CB00C795DE /* FSCalendar+Deprecated.m in Sources */ = {isa = PBXBuildFile; fileRef = 300036CD1D9252CB00C795DE /* FSCalendar+Deprecated.m */; }; - 300036EE1D9252CB00C795DE /* FSCalendar+IBExtension.m in Sources */ = {isa = PBXBuildFile; fileRef = 300036CF1D9252CB00C795DE /* FSCalendar+IBExtension.m */; }; 300036EF1D9252CB00C795DE /* FSCalendar.m in Sources */ = {isa = PBXBuildFile; fileRef = 300036D11D9252CB00C795DE /* FSCalendar.m */; }; 300036F01D9252CB00C795DE /* FSCalendarAnimator.m in Sources */ = {isa = PBXBuildFile; fileRef = 300036D31D9252CB00C795DE /* FSCalendarAnimator.m */; }; 300036F11D9252CB00C795DE /* FSCalendarAppearance.m in Sources */ = {isa = PBXBuildFile; fileRef = 300036D51D9252CB00C795DE /* FSCalendarAppearance.m */; }; 300036F21D9252CB00C795DE /* FSCalendarCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 300036D71D9252CB00C795DE /* FSCalendarCell.m */; }; 300036F31D9252CB00C795DE /* FSCalendarCollectionView.m in Sources */ = {isa = PBXBuildFile; fileRef = 300036D91D9252CB00C795DE /* FSCalendarCollectionView.m */; }; - 300036F51D9252CB00C795DE /* FSCalendarEventIndicator.m in Sources */ = {isa = PBXBuildFile; fileRef = 300036DE1D9252CB00C795DE /* FSCalendarEventIndicator.m */; }; 300036F61D9252CB00C795DE /* FSCalendarFlowLayout.m in Sources */ = {isa = PBXBuildFile; fileRef = 300036E01D9252CB00C795DE /* FSCalendarFlowLayout.m */; }; 300036F71D9252CB00C795DE /* FSCalendarHeader.m in Sources */ = {isa = PBXBuildFile; fileRef = 300036E21D9252CB00C795DE /* FSCalendarHeader.m */; }; 300036F81D9252CB00C795DE /* FSCalendarScopeHandle.m in Sources */ = {isa = PBXBuildFile; fileRef = 300036E41D9252CB00C795DE /* FSCalendarScopeHandle.m */; }; @@ -61,8 +59,6 @@ /* Begin PBXFileReference section */ 300036CD1D9252CB00C795DE /* FSCalendar+Deprecated.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "FSCalendar+Deprecated.m"; sourceTree = ""; }; - 300036CE1D9252CB00C795DE /* FSCalendar+IBExtension.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "FSCalendar+IBExtension.h"; sourceTree = ""; }; - 300036CF1D9252CB00C795DE /* FSCalendar+IBExtension.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "FSCalendar+IBExtension.m"; sourceTree = ""; }; 300036D01D9252CB00C795DE /* FSCalendar.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FSCalendar.h; sourceTree = ""; }; 300036D11D9252CB00C795DE /* FSCalendar.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FSCalendar.m; sourceTree = ""; }; 300036D21D9252CB00C795DE /* FSCalendarAnimator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FSCalendarAnimator.h; sourceTree = ""; }; @@ -74,8 +70,6 @@ 300036D81D9252CB00C795DE /* FSCalendarCollectionView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FSCalendarCollectionView.h; sourceTree = ""; }; 300036D91D9252CB00C795DE /* FSCalendarCollectionView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FSCalendarCollectionView.m; sourceTree = ""; }; 300036DC1D9252CB00C795DE /* FSCalendarDynamicHeader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FSCalendarDynamicHeader.h; sourceTree = ""; }; - 300036DD1D9252CB00C795DE /* FSCalendarEventIndicator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FSCalendarEventIndicator.h; sourceTree = ""; }; - 300036DE1D9252CB00C795DE /* FSCalendarEventIndicator.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FSCalendarEventIndicator.m; sourceTree = ""; }; 300036DF1D9252CB00C795DE /* FSCalendarFlowLayout.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FSCalendarFlowLayout.h; sourceTree = ""; }; 300036E01D9252CB00C795DE /* FSCalendarFlowLayout.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FSCalendarFlowLayout.m; sourceTree = ""; }; 300036E11D9252CB00C795DE /* FSCalendarHeader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FSCalendarHeader.h; sourceTree = ""; }; @@ -141,8 +135,6 @@ 300036D81D9252CB00C795DE /* FSCalendarCollectionView.h */, 300036D91D9252CB00C795DE /* FSCalendarCollectionView.m */, 300036DC1D9252CB00C795DE /* FSCalendarDynamicHeader.h */, - 300036DD1D9252CB00C795DE /* FSCalendarEventIndicator.h */, - 300036DE1D9252CB00C795DE /* FSCalendarEventIndicator.m */, 300036DF1D9252CB00C795DE /* FSCalendarFlowLayout.h */, 300036E01D9252CB00C795DE /* FSCalendarFlowLayout.m */, 300036E11D9252CB00C795DE /* FSCalendarHeader.h */, @@ -156,8 +148,6 @@ 3055B1CC1DA933D0002AFA13 /* FSCalendarExtensions.h */, 3055B1CD1DA933D0002AFA13 /* FSCalendarExtensions.m */, 300036CD1D9252CB00C795DE /* FSCalendar+Deprecated.m */, - 300036CE1D9252CB00C795DE /* FSCalendar+IBExtension.h */, - 300036CF1D9252CB00C795DE /* FSCalendar+IBExtension.m */, 300036E71D9252CB00C795DE /* Info.plist */, ); name = FSCalendar; @@ -343,11 +333,9 @@ files = ( 300036F91D9252CB00C795DE /* FSCalendarStickyHeader.m in Sources */, 30A33A0E1DB1CA8D0039BEA3 /* FSCalendarConstants.m in Sources */, - 300036EE1D9252CB00C795DE /* FSCalendar+IBExtension.m in Sources */, 300036ED1D9252CB00C795DE /* FSCalendar+Deprecated.m in Sources */, 300036F01D9252CB00C795DE /* FSCalendarAnimator.m in Sources */, 300036F31D9252CB00C795DE /* FSCalendarCollectionView.m in Sources */, - 300036F51D9252CB00C795DE /* FSCalendarEventIndicator.m in Sources */, 300036F61D9252CB00C795DE /* FSCalendarFlowLayout.m in Sources */, 300036F71D9252CB00C795DE /* FSCalendarHeader.m in Sources */, 3055B1CE1DA933D0002AFA13 /* FSCalendarExtensions.m in Sources */, From ed7424741a8e0ebd9ba93e80c8cd800edf2ea625 Mon Sep 17 00:00:00 2001 From: Wenchao Ding Date: Sat, 22 Oct 2016 21:43:19 +0800 Subject: [PATCH 2/5] Add ISSUE_TEMPLATE.md --- .github/ISSUE_TEMPLATE.md.md | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 .github/ISSUE_TEMPLATE.md.md diff --git a/.github/ISSUE_TEMPLATE.md.md b/.github/ISSUE_TEMPLATE.md.md new file mode 100644 index 00000000..0139e999 --- /dev/null +++ b/.github/ISSUE_TEMPLATE.md.md @@ -0,0 +1,10 @@ + +## The following informations are requested in a bug report +* A brief bug description. +* Stack trace. +* Integration method.`(manually/cocoapods/carthage)` +* Full steps to reproduce. +* Device modal and iOS version. `e.g. iPhone 5s iOS8.1` +* Xcode version. `e.g. Xcode 8.0` +* FSCalendar version. `e.g. FSCalenda 2.4.0` +* Does this happen in the demo project? Which one? Or a link to another demo project. \ No newline at end of file From d49bf95f1e696ffaed9b71cd1a65765c53201400 Mon Sep 17 00:00:00 2001 From: Wenchao Ding Date: Thu, 27 Oct 2016 10:01:46 +0800 Subject: [PATCH 3/5] Fix issue #463 --- FSCalendar/FSCalendar.m | 5 ----- 1 file changed, 5 deletions(-) diff --git a/FSCalendar/FSCalendar.m b/FSCalendar/FSCalendar.m index 801feaa0..c393c842 100644 --- a/FSCalendar/FSCalendar.m +++ b/FSCalendar/FSCalendar.m @@ -629,11 +629,6 @@ - (BOOL)collectionView:(UICollectionView *)collectionView shouldSelectItemAtInde if (cell.date && [self isDateInRange:cell.date] && !_supressEvent) { shouldSelect &= [self shouldSelectDate:cell.date]; } - if (shouldSelect) { - if (!self.allowsMultipleSelection && self.selectedDate) { - [self deselectDate:self.selectedDate]; - } - } return shouldSelect && [self isDateInRange:cell.date]; } From fb915abc116a94a8bc27db38fb3ac5777fd68a07 Mon Sep 17 00:00:00 2001 From: Wenchao Ding Date: Thu, 27 Oct 2016 16:39:12 +0800 Subject: [PATCH 4/5] FSCalendarSeparators --- .../project.pbxproj | 12 +- Example/FSCalendar.xcodeproj/project.pbxproj | 24 +-- Example/HidePlaceholderViewController.m | 2 + Example/StoryboardExampleViewController.m | 18 +-- FSCalendar/FSCalendar.m | 10 +- FSCalendar/FSCalendarAnimator.h | 4 +- FSCalendar/FSCalendarAppearance.h | 11 ++ FSCalendar/FSCalendarAppearance.m | 8 + FSCalendar/FSCalendarCollectionView.h | 5 + FSCalendar/FSCalendarCollectionView.m | 22 +++ ...out.h => FSCalendarCollectionViewLayout.h} | 5 +- FSCalendar/FSCalendarCollectionViewLayout.m | 150 ++++++++++++++++++ FSCalendar/FSCalendarConstants.h | 12 +- FSCalendar/FSCalendarConstants.m | 1 + FSCalendar/FSCalendarDynamicHeader.h | 4 +- FSCalendar/FSCalendarFlowLayout.m | 85 ---------- FSCalendar/FSCalendarStickyHeader.m | 10 +- .../SwiftExample.xcodeproj/project.pbxproj | 12 +- .../project.pbxproj | 12 +- 19 files changed, 257 insertions(+), 150 deletions(-) rename FSCalendar/{FSCalendarFlowLayout.h => FSCalendarCollectionViewLayout.h} (63%) create mode 100644 FSCalendar/FSCalendarCollectionViewLayout.m delete mode 100644 FSCalendar/FSCalendarFlowLayout.m diff --git a/DynamicTodayExtensionExample/DynamicTodayExtensionExample.xcodeproj/project.pbxproj b/DynamicTodayExtensionExample/DynamicTodayExtensionExample.xcodeproj/project.pbxproj index a2cebaa4..79bf688a 100644 --- a/DynamicTodayExtensionExample/DynamicTodayExtensionExample.xcodeproj/project.pbxproj +++ b/DynamicTodayExtensionExample/DynamicTodayExtensionExample.xcodeproj/project.pbxproj @@ -24,12 +24,12 @@ 3052336B1D8170E50070AAFE /* FSCalendarAppearance.m in Sources */ = {isa = PBXBuildFile; fileRef = 305233501D8170E50070AAFE /* FSCalendarAppearance.m */; }; 3052336C1D8170E50070AAFE /* FSCalendarCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 305233521D8170E50070AAFE /* FSCalendarCell.m */; }; 3052336D1D8170E50070AAFE /* FSCalendarCollectionView.m in Sources */ = {isa = PBXBuildFile; fileRef = 305233541D8170E50070AAFE /* FSCalendarCollectionView.m */; }; - 305233701D8170E50070AAFE /* FSCalendarFlowLayout.m in Sources */ = {isa = PBXBuildFile; fileRef = 3052335B1D8170E50070AAFE /* FSCalendarFlowLayout.m */; }; 305233711D8170E50070AAFE /* FSCalendarHeader.m in Sources */ = {isa = PBXBuildFile; fileRef = 3052335D1D8170E50070AAFE /* FSCalendarHeader.m */; }; 305233721D8170E50070AAFE /* FSCalendarScopeHandle.m in Sources */ = {isa = PBXBuildFile; fileRef = 3052335F1D8170E50070AAFE /* FSCalendarScopeHandle.m */; }; 305233731D8170E50070AAFE /* FSCalendarStickyHeader.m in Sources */ = {isa = PBXBuildFile; fileRef = 305233611D8170E50070AAFE /* FSCalendarStickyHeader.m */; }; 305233741D8170E50070AAFE /* Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 305233621D8170E50070AAFE /* Info.plist */; }; 3055B1CB1DA933AD002AFA13 /* FSCalendarExtensions.m in Sources */ = {isa = PBXBuildFile; fileRef = 3055B1CA1DA933AD002AFA13 /* FSCalendarExtensions.m */; }; + 30623F701DC1F46800FA31B3 /* FSCalendarCollectionViewLayout.m in Sources */ = {isa = PBXBuildFile; fileRef = 30623F6F1DC1F46800FA31B3 /* FSCalendarCollectionViewLayout.m */; }; 30A33A0B1DB1CA640039BEA3 /* FSCalendarConstants.m in Sources */ = {isa = PBXBuildFile; fileRef = 30A33A0A1DB1CA640039BEA3 /* FSCalendarConstants.m */; }; /* End PBXBuildFile section */ @@ -87,8 +87,6 @@ 305233531D8170E50070AAFE /* FSCalendarCollectionView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FSCalendarCollectionView.h; sourceTree = ""; }; 305233541D8170E50070AAFE /* FSCalendarCollectionView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FSCalendarCollectionView.m; sourceTree = ""; }; 305233571D8170E50070AAFE /* FSCalendarDynamicHeader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FSCalendarDynamicHeader.h; sourceTree = ""; }; - 3052335A1D8170E50070AAFE /* FSCalendarFlowLayout.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FSCalendarFlowLayout.h; sourceTree = ""; }; - 3052335B1D8170E50070AAFE /* FSCalendarFlowLayout.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FSCalendarFlowLayout.m; sourceTree = ""; }; 3052335C1D8170E50070AAFE /* FSCalendarHeader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FSCalendarHeader.h; sourceTree = ""; }; 3052335D1D8170E50070AAFE /* FSCalendarHeader.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FSCalendarHeader.m; sourceTree = ""; }; 3052335E1D8170E50070AAFE /* FSCalendarScopeHandle.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FSCalendarScopeHandle.h; sourceTree = ""; }; @@ -98,6 +96,8 @@ 305233621D8170E50070AAFE /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 3055B1C91DA933AD002AFA13 /* FSCalendarExtensions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FSCalendarExtensions.h; sourceTree = ""; }; 3055B1CA1DA933AD002AFA13 /* FSCalendarExtensions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FSCalendarExtensions.m; sourceTree = ""; }; + 30623F6E1DC1F46800FA31B3 /* FSCalendarCollectionViewLayout.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FSCalendarCollectionViewLayout.h; sourceTree = ""; }; + 30623F6F1DC1F46800FA31B3 /* FSCalendarCollectionViewLayout.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FSCalendarCollectionViewLayout.m; sourceTree = ""; }; 30A33A091DB1CA640039BEA3 /* FSCalendarConstants.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FSCalendarConstants.h; sourceTree = ""; }; 30A33A0A1DB1CA640039BEA3 /* FSCalendarConstants.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FSCalendarConstants.m; sourceTree = ""; }; /* End PBXFileReference section */ @@ -200,8 +200,8 @@ 305233541D8170E50070AAFE /* FSCalendarCollectionView.m */, 30A33A091DB1CA640039BEA3 /* FSCalendarConstants.h */, 30A33A0A1DB1CA640039BEA3 /* FSCalendarConstants.m */, - 3052335A1D8170E50070AAFE /* FSCalendarFlowLayout.h */, - 3052335B1D8170E50070AAFE /* FSCalendarFlowLayout.m */, + 30623F6E1DC1F46800FA31B3 /* FSCalendarCollectionViewLayout.h */, + 30623F6F1DC1F46800FA31B3 /* FSCalendarCollectionViewLayout.m */, 3052335C1D8170E50070AAFE /* FSCalendarHeader.h */, 3052335D1D8170E50070AAFE /* FSCalendarHeader.m */, 3052335E1D8170E50070AAFE /* FSCalendarScopeHandle.h */, @@ -333,12 +333,12 @@ files = ( 30A33A0B1DB1CA640039BEA3 /* FSCalendarConstants.m in Sources */, 305233721D8170E50070AAFE /* FSCalendarScopeHandle.m in Sources */, + 30623F701DC1F46800FA31B3 /* FSCalendarCollectionViewLayout.m in Sources */, 305233691D8170E50070AAFE /* FSCalendar.m in Sources */, 305233671D8170E50070AAFE /* FSCalendar+Deprecated.m in Sources */, 3052336B1D8170E50070AAFE /* FSCalendarAppearance.m in Sources */, 305233731D8170E50070AAFE /* FSCalendarStickyHeader.m in Sources */, 305233711D8170E50070AAFE /* FSCalendarHeader.m in Sources */, - 305233701D8170E50070AAFE /* FSCalendarFlowLayout.m in Sources */, 3055B1CB1DA933AD002AFA13 /* FSCalendarExtensions.m in Sources */, 3052336C1D8170E50070AAFE /* FSCalendarCell.m in Sources */, 3052336D1D8170E50070AAFE /* FSCalendarCollectionView.m in Sources */, diff --git a/Example/FSCalendar.xcodeproj/project.pbxproj b/Example/FSCalendar.xcodeproj/project.pbxproj index 1d03ba0b..75a2cba0 100644 --- a/Example/FSCalendar.xcodeproj/project.pbxproj +++ b/Example/FSCalendar.xcodeproj/project.pbxproj @@ -24,9 +24,9 @@ 3092253A1B905C4300123031 /* FSCalendarConstants.h in Headers */ = {isa = PBXBuildFile; fileRef = 309225381B905C4300123031 /* FSCalendarConstants.h */; settings = {ATTRIBUTES = (Public, ); }; }; 3092253B1B905C4300123031 /* FSCalendarConstants.m in Sources */ = {isa = PBXBuildFile; fileRef = 309225391B905C4300123031 /* FSCalendarConstants.m */; }; 3092253C1B905C4300123031 /* FSCalendarConstants.m in Sources */ = {isa = PBXBuildFile; fileRef = 309225391B905C4300123031 /* FSCalendarConstants.m */; }; - 3095398F1C38D66C00BD37AA /* FSCalendarFlowLayout.h in Headers */ = {isa = PBXBuildFile; fileRef = 3095398D1C38D66C00BD37AA /* FSCalendarFlowLayout.h */; settings = {ATTRIBUTES = (Private, ); }; }; - 309539901C38D66C00BD37AA /* FSCalendarFlowLayout.m in Sources */ = {isa = PBXBuildFile; fileRef = 3095398E1C38D66C00BD37AA /* FSCalendarFlowLayout.m */; }; - 309539911C38D66C00BD37AA /* FSCalendarFlowLayout.m in Sources */ = {isa = PBXBuildFile; fileRef = 3095398E1C38D66C00BD37AA /* FSCalendarFlowLayout.m */; }; + 3095398F1C38D66C00BD37AA /* FSCalendarCollectionViewLayout.h in Headers */ = {isa = PBXBuildFile; fileRef = 3095398D1C38D66C00BD37AA /* FSCalendarCollectionViewLayout.h */; settings = {ATTRIBUTES = (Private, ); }; }; + 309539901C38D66C00BD37AA /* FSCalendarCollectionViewLayout.m in Sources */ = {isa = PBXBuildFile; fileRef = 3095398E1C38D66C00BD37AA /* FSCalendarCollectionViewLayout.m */; }; + 309539911C38D66C00BD37AA /* FSCalendarCollectionViewLayout.m in Sources */ = {isa = PBXBuildFile; fileRef = 3095398E1C38D66C00BD37AA /* FSCalendarCollectionViewLayout.m */; }; 309A42011D992C4A004E86CB /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 309A42001D992C4A004E86CB /* Images.xcassets */; }; 30B0BA9B1B8D8BC9004B9476 /* FSCalendar.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = EE638CE21B8A1F550006DD1A /* FSCalendar.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 30B0BAD01B8D8E23004B9476 /* FSCalendar.m in Sources */ = {isa = PBXBuildFile; fileRef = 30B0BAC01B8D8E22004B9476 /* FSCalendar.m */; }; @@ -113,8 +113,8 @@ 308B58D71CC08FFA004E812D /* ButtonsViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ButtonsViewController.m; sourceTree = SOURCE_ROOT; }; 309225381B905C4300123031 /* FSCalendarConstants.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FSCalendarConstants.h; sourceTree = ""; }; 309225391B905C4300123031 /* FSCalendarConstants.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FSCalendarConstants.m; sourceTree = ""; }; - 3095398D1C38D66C00BD37AA /* FSCalendarFlowLayout.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FSCalendarFlowLayout.h; sourceTree = ""; }; - 3095398E1C38D66C00BD37AA /* FSCalendarFlowLayout.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FSCalendarFlowLayout.m; sourceTree = ""; }; + 3095398D1C38D66C00BD37AA /* FSCalendarCollectionViewLayout.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FSCalendarCollectionViewLayout.h; sourceTree = ""; }; + 3095398E1C38D66C00BD37AA /* FSCalendarCollectionViewLayout.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FSCalendarCollectionViewLayout.m; sourceTree = ""; }; 309A42001D992C4A004E86CB /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = SOURCE_ROOT; }; 30B0BABF1B8D8E22004B9476 /* FSCalendar.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FSCalendar.h; sourceTree = ""; }; 30B0BAC01B8D8E22004B9476 /* FSCalendar.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FSCalendar.m; sourceTree = ""; }; @@ -227,12 +227,12 @@ 30B0BAC41B8D8E22004B9476 /* FSCalendarCell.m */, EEC9C0371BDC9E7000383A07 /* FSCalendarCollectionView.h */, EEC9C0381BDC9E7000383A07 /* FSCalendarCollectionView.m */, + 3095398D1C38D66C00BD37AA /* FSCalendarCollectionViewLayout.h */, + 3095398E1C38D66C00BD37AA /* FSCalendarCollectionViewLayout.m */, 30B0BAC61B8D8E22004B9476 /* FSCalendarHeader.h */, 30B0BAC71B8D8E22004B9476 /* FSCalendarHeader.m */, 30FCB3941BAAD112002B87AD /* FSCalendarStickyHeader.h */, 30FCB3951BAAD112002B87AD /* FSCalendarStickyHeader.m */, - 3095398D1C38D66C00BD37AA /* FSCalendarFlowLayout.h */, - 3095398E1C38D66C00BD37AA /* FSCalendarFlowLayout.m */, 30CEF8FE1C950C1F008EAFB1 /* FSCalendarAnimator.h */, 30CEF8FF1C950C1F008EAFB1 /* FSCalendarAnimator.m */, 3055B1C01DA9323A002AFA13 /* FSCalendarExtensions.h */, @@ -395,7 +395,7 @@ EEC9C0391BDC9E7000383A07 /* FSCalendarCollectionView.h in Headers */, 30FCB3961BAAD112002B87AD /* FSCalendarStickyHeader.h in Headers */, 3065CA961CD31B81006C218D /* FSCalendarScopeHandle.h in Headers */, - 3095398F1C38D66C00BD37AA /* FSCalendarFlowLayout.h in Headers */, + 3095398F1C38D66C00BD37AA /* FSCalendarCollectionViewLayout.h in Headers */, 3055B1C21DA9323A002AFA13 /* FSCalendarExtensions.h in Headers */, 30CEF9001C950C1F008EAFB1 /* FSCalendarAnimator.h in Headers */, 30B0BB031B8D9B6D004B9476 /* FSCalendarDynamicHeader.h in Headers */, @@ -555,7 +555,7 @@ 3065CAA81CD3506A006C218D /* FSCalendar+Deprecated.m in Sources */, EE638CD31B89DBE90006DD1A /* AppDelegate.m in Sources */, 3092253B1B905C4300123031 /* FSCalendarConstants.m in Sources */, - 309539901C38D66C00BD37AA /* FSCalendarFlowLayout.m in Sources */, + 309539901C38D66C00BD37AA /* FSCalendarCollectionViewLayout.m in Sources */, 30F5D85A1B9FC4BB00C1C201 /* MultipleSelectionViewController.m in Sources */, 30FCB3971BAAD112002B87AD /* FSCalendarStickyHeader.m in Sources */, 30B0BAD21B8D8E23004B9476 /* FSCalendarCell.m in Sources */, @@ -588,7 +588,7 @@ 30B0BAF81B8D9AC1004B9476 /* FSCalendarHeader.m in Sources */, 3092253C1B905C4300123031 /* FSCalendarConstants.m in Sources */, 3055B1C41DA9323A002AFA13 /* FSCalendarExtensions.m in Sources */, - 309539911C38D66C00BD37AA /* FSCalendarFlowLayout.m in Sources */, + 309539911C38D66C00BD37AA /* FSCalendarCollectionViewLayout.m in Sources */, 3065CA981CD31B81006C218D /* FSCalendarScopeHandle.m in Sources */, 30CEF9021C950C1F008EAFB1 /* FSCalendarAnimator.m in Sources */, 30FCB3981BAAD112002B87AD /* FSCalendarStickyHeader.m in Sources */, @@ -699,7 +699,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 = 7.0; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; @@ -739,7 +739,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 = 7.0; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; VALIDATE_PRODUCT = YES; diff --git a/Example/HidePlaceholderViewController.m b/Example/HidePlaceholderViewController.m index c7b5c29f..1fdfbf81 100644 --- a/Example/HidePlaceholderViewController.m +++ b/Example/HidePlaceholderViewController.m @@ -96,6 +96,8 @@ - (void)viewDidLoad self.gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian]; + self.calendar.appearance.separators = FSCalendarSeparatorInterRows; + } - (NSDate *)minimumDateForCalendar:(FSCalendar *)calendar diff --git a/Example/StoryboardExampleViewController.m b/Example/StoryboardExampleViewController.m index 6c78f5ac..e7b43925 100644 --- a/Example/StoryboardExampleViewController.m +++ b/Example/StoryboardExampleViewController.m @@ -53,18 +53,18 @@ - (void)viewDidLoad // [_calendar selectDate:[self.dateFormatter1 dateFromString:@"2015/10/05"]]; - _datesShouldNotBeSelected = @[@"2015/08/07", - @"2015/09/07", - @"2015/10/07", - @"2015/11/07", - @"2015/12/07", + _datesShouldNotBeSelected = @[@"2016/08/07", + @"2016/09/07", + @"2016/10/07", + @"2016/11/07", + @"2016/12/07", @"2016/01/07", @"2016/02/07"]; - _datesWithEvent = @[@"2015-10-03", - @"2015-10-07", - @"2015-10-15", - @"2015-10-25"]; + _datesWithEvent = @[@"2016-10-03", + @"2016-10-07", + @"2016-10-15", + @"2016-10-25"]; // self.calendar.appearance.weekdayBackground = [UIColor cyanColor]; diff --git a/FSCalendar/FSCalendar.m b/FSCalendar/FSCalendar.m index c393c842..2d45bd2a 100644 --- a/FSCalendar/FSCalendar.m +++ b/FSCalendar/FSCalendar.m @@ -10,7 +10,7 @@ #import "FSCalendarHeader.h" #import "FSCalendarStickyHeader.h" #import "FSCalendarCell.h" -#import "FSCalendarFlowLayout.h" +#import "FSCalendarCollectionViewLayout.h" #import "FSCalendarAnimator.h" #import "FSCalendarScopeHandle.h" @@ -106,8 +106,8 @@ @interface FSCalendar () @property (weak , nonatomic) UIImageView *weekdayView; @property (weak , nonatomic) FSCalendarScopeHandle *scopeHandle; @property (weak , nonatomic) FSCalendarCollectionView *collectionView; -@property (weak , nonatomic) FSCalendarFlowLayout *collectionViewLayout; @property (strong, nonatomic) FSCalendarAnimator *animator; +@property (weak , nonatomic) FSCalendarCollectionViewLayout *collectionViewLayout; @property (weak , nonatomic) FSCalendarHeader *header; @property (weak , nonatomic) FSCalendarHeaderTouchDeliver *deliver; @@ -262,7 +262,7 @@ - (void)initialize [contentView addSubview:daysContainer]; self.daysContainer = daysContainer; - FSCalendarFlowLayout *collectionViewLayout = [[FSCalendarFlowLayout alloc] init]; + FSCalendarCollectionViewLayout *collectionViewLayout = [[FSCalendarCollectionViewLayout alloc] init]; collectionViewLayout.calendar = self; FSCalendarCollectionView *collectionView = [[FSCalendarCollectionView alloc] initWithFrame:CGRectZero @@ -287,12 +287,12 @@ - (void)initialize if (!FSCalendarInAppExtension) { UIView *view = [[UIView alloc] initWithFrame:CGRectZero]; - view.backgroundColor = FSCalendarStandardSeparatorColor; + view.backgroundColor = FSCalendarStandardLineColor; [self addSubview:view]; self.topBorder = view; view = [[UIView alloc] initWithFrame:CGRectZero]; - view.backgroundColor = FSCalendarStandardSeparatorColor; + view.backgroundColor = FSCalendarStandardLineColor; [self addSubview:view]; self.bottomBorder = view; diff --git a/FSCalendar/FSCalendarAnimator.h b/FSCalendar/FSCalendarAnimator.h index 056433bf..d37dee69 100644 --- a/FSCalendar/FSCalendarAnimator.h +++ b/FSCalendar/FSCalendarAnimator.h @@ -8,7 +8,7 @@ #import "FSCalendar.h" #import "FSCalendarCollectionView.h" -#import "FSCalendarFlowLayout.h" +#import "FSCalendarCollectionViewLayout.h" #import "FSCalendarScopeHandle.h" typedef NS_ENUM(NSUInteger, FSCalendarTransition) { @@ -25,7 +25,7 @@ typedef NS_ENUM(NSUInteger, FSCalendarTransitionState) { @property (weak, nonatomic) FSCalendar *calendar; @property (weak, nonatomic) FSCalendarCollectionView *collectionView; -@property (weak, nonatomic) FSCalendarFlowLayout *collectionViewLayout; +@property (weak, nonatomic) FSCalendarCollectionViewLayout *collectionViewLayout; @property (assign, nonatomic) FSCalendarTransition transition; @property (assign, nonatomic) FSCalendarTransitionState state; diff --git a/FSCalendar/FSCalendarAppearance.h b/FSCalendar/FSCalendarAppearance.h index 549dfaa2..2c82bc3b 100644 --- a/FSCalendar/FSCalendarAppearance.h +++ b/FSCalendar/FSCalendarAppearance.h @@ -31,6 +31,11 @@ typedef NS_OPTIONS(NSUInteger, FSCalendarCaseOptions) { FSCalendarCaseOptionsWeekdayUsesSingleUpperCase = 2 << 4, }; +typedef NS_OPTIONS(NSUInteger, FSCalendarSeparators) { + FSCalendarSeparatorInterRows = 1 << 0, + FSCalendarSeparatorInterColumns = 1 << 1 // Will implemented soon +}; + /** * FSCalendarAppearance determines the fonts and colors of components in the calendar. * @@ -208,6 +213,12 @@ typedef NS_OPTIONS(NSUInteger, FSCalendarCaseOptions) { */ @property (assign, nonatomic) FSCalendarCaseOptions caseOptions; +/** + * The line integrations for calendar. + * + */ +@property (assign, nonatomic) FSCalendarSeparators separators; + /** * A Boolean value indicates whether the calendar should adjust font size by its content size. * diff --git a/FSCalendar/FSCalendarAppearance.m b/FSCalendar/FSCalendarAppearance.m index 6d97b2ce..57b31cfa 100644 --- a/FSCalendar/FSCalendarAppearance.m +++ b/FSCalendar/FSCalendarAppearance.m @@ -602,6 +602,14 @@ - (void)setCaseOptions:(FSCalendarCaseOptions)caseOptions } } +- (void)setSeparators:(FSCalendarSeparators)separators +{ + if (_separators != separators) { + _separators = separators; + [_calendar.collectionView.collectionViewLayout invalidateLayout]; + } +} + - (void)invalidateAppearance { [self invalidateFonts]; diff --git a/FSCalendar/FSCalendarCollectionView.h b/FSCalendar/FSCalendarCollectionView.h index 1d0f577d..2b955a9d 100644 --- a/FSCalendar/FSCalendarCollectionView.h +++ b/FSCalendar/FSCalendarCollectionView.h @@ -11,3 +11,8 @@ @interface FSCalendarCollectionView : UICollectionView @end + + +@interface FSCalendarSeparator : UICollectionReusableView + +@end diff --git a/FSCalendar/FSCalendarCollectionView.m b/FSCalendar/FSCalendarCollectionView.m index bc31bbef..bc8bb023 100644 --- a/FSCalendar/FSCalendarCollectionView.m +++ b/FSCalendar/FSCalendarCollectionView.m @@ -8,6 +8,7 @@ #import "FSCalendarCollectionView.h" #import "FSCalendarExtensions.h" +#import "FSCalendarConstants.h" @interface FSCalendarCollectionView () @@ -68,3 +69,24 @@ - (void)setScrollsToTop:(BOOL)scrollsToTop @end + +@implementation FSCalendarSeparator + +- (instancetype)initWithFrame:(CGRect)frame +{ + self = [super initWithFrame:frame]; + if (self) { + self.backgroundColor = FSCalendarStandardSeparatorColor; + } + return self; +} + +- (void)applyLayoutAttributes:(UICollectionViewLayoutAttributes *)layoutAttributes +{ + self.frame = layoutAttributes.frame; +} + +@end + + + diff --git a/FSCalendar/FSCalendarFlowLayout.h b/FSCalendar/FSCalendarCollectionViewLayout.h similarity index 63% rename from FSCalendar/FSCalendarFlowLayout.h rename to FSCalendar/FSCalendarCollectionViewLayout.h index fc6f3230..84e80888 100644 --- a/FSCalendar/FSCalendarFlowLayout.h +++ b/FSCalendar/FSCalendarCollectionViewLayout.h @@ -10,11 +10,8 @@ @class FSCalendar; -typedef NS_ENUM(NSUInteger, FSCalendarScope); - -@interface FSCalendarFlowLayout : UICollectionViewFlowLayout +@interface FSCalendarCollectionViewLayout : UICollectionViewFlowLayout @property (weak, nonatomic) FSCalendar *calendar; - @end diff --git a/FSCalendar/FSCalendarCollectionViewLayout.m b/FSCalendar/FSCalendarCollectionViewLayout.m new file mode 100644 index 00000000..db98bd87 --- /dev/null +++ b/FSCalendar/FSCalendarCollectionViewLayout.m @@ -0,0 +1,150 @@ +// +// FSCalendarAnimationLayout.m +// FSCalendar +// +// Created by dingwenchao on 1/3/16. +// Copyright © 2016 wenchaoios. All rights reserved. +// + +#import "FSCalendarCollectionViewLayout.h" +#import "FSCalendar.h" +#import "FSCalendarDynamicHeader.h" +#import "FSCalendarCollectionView.h" +#import "FSCalendarExtensions.h" +#import "FSCalendarConstants.h" +#import + +#define kFSCalendarSeparatorInterRows @"FSCalendarSeparatorInterRows" +#define kFSCalendarSeparatorInterColumns @"FSCalendarSeparatorInterColumns" + +@interface FSCalendarCollectionViewLayout () + +@end + +@implementation FSCalendarCollectionViewLayout + +- (instancetype)init +{ + self = [super init]; + if (self) { + + self.scrollDirection = UICollectionViewScrollDirectionHorizontal; + self.minimumInteritemSpacing = 0; + self.minimumLineSpacing = 0; + self.itemSize = CGSizeMake(1, 1); + self.sectionInset = UIEdgeInsetsZero; + + [self registerClass:[FSCalendarSeparator class] forDecorationViewOfKind:kFSCalendarSeparatorInterRows]; + + } + return self; +} + +- (void)prepareLayout +{ + [super prepareLayout]; + + CGFloat rowHeight = self.calendar.preferredRowHeight; + + if (!self.calendar.floatingMode) { + + self.headerReferenceSize = CGSizeZero; + + CGFloat padding = self.calendar.preferredPadding; + if (self.scrollDirection == UICollectionViewScrollDirectionHorizontal) { + padding = FSCalendarFloor(padding); + rowHeight = FSCalendarFloor(rowHeight*2)*0.5-1; // Round to nearest multiple of 0.5. e.g. (16.8->16.5),(16.2->16.0) + } + self.sectionInset = UIEdgeInsetsMake(padding, 0, padding, 0); + switch (self.calendar.scope) { + + case FSCalendarScopeMonth: { + + CGFloat columnWidth = self.collectionView.fs_width/7.0-(self.scrollDirection == UICollectionViewScrollDirectionVertical)*0.1; + CGSize itemSize = CGSizeMake(columnWidth,rowHeight); + self.itemSize = itemSize; + + break; + } + case FSCalendarScopeWeek: { + + CGSize itemSize = CGSizeMake(self.collectionView.fs_width/7.0, rowHeight); + self.itemSize = itemSize; + + break; + + } + + } + } else { + + CGFloat headerHeight = self.calendar.preferredWeekdayHeight*1.5+self.calendar.preferredHeaderHeight; + self.headerReferenceSize = CGSizeMake(self.collectionView.fs_width, headerHeight); + + CGFloat columnWidth = self.collectionView.fs_width/7.0-(self.scrollDirection == UICollectionViewScrollDirectionVertical)*0.1; + + CGSize itemSize = CGSizeMake(columnWidth,rowHeight); + self.itemSize = itemSize; + + self.sectionInset = UIEdgeInsetsZero; + + } + +} + +- (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect +{ + NSArray *attributesArray = [super layoutAttributesForElementsInRect:rect]; + + // Clean on week mode + if (self.calendar.scope == FSCalendarScopeWeek) { + return attributesArray; + } + + if ((self.calendar.appearance.separators & FSCalendarSeparatorInterRows) != 0) { + + // Get row leadings + NSArray *visibleRows = [attributesArray filteredArrayUsingPredicate:[NSPredicate predicateWithBlock:^BOOL(UICollectionViewLayoutAttributes * _Nullable evaluatedObject, NSDictionary * _Nullable bindings) { + + if (evaluatedObject.representedElementCategory != UICollectionElementCategoryCell) { + return NO; + } + + NSDate *currentPage = [self.calendar.gregorian dateByAddingUnit:NSCalendarUnitMonth value:evaluatedObject.indexPath.section toDate:[self.calendar beginingOfMonth:self.calendar.minimumDate] options:0]; + NSInteger numberOfRows = [self.calendar numberOfRowsInMonth:currentPage]; + + switch (self.scrollDirection) { + case UICollectionViewScrollDirectionHorizontal: { + return evaluatedObject.indexPath.item < numberOfRows-1; + } + case UICollectionViewScrollDirectionVertical: { + return evaluatedObject.indexPath.item%7==0 && evaluatedObject.indexPath.item/7 *weekdays; @property (readonly, nonatomic) BOOL floatingMode; diff --git a/FSCalendar/FSCalendarFlowLayout.m b/FSCalendar/FSCalendarFlowLayout.m deleted file mode 100644 index cdfc085a..00000000 --- a/FSCalendar/FSCalendarFlowLayout.m +++ /dev/null @@ -1,85 +0,0 @@ -// -// FSCalendarAnimationLayout.m -// FSCalendar -// -// Created by dingwenchao on 1/3/16. -// Copyright © 2016 wenchaoios. All rights reserved. -// - -#import "FSCalendarFlowLayout.h" -#import "FSCalendarDynamicHeader.h" -#import "FSCalendar.h" -#import "FSCalendarExtensions.h" -#import - -@implementation FSCalendarFlowLayout - -- (instancetype)init -{ - self = [super init]; - if (self) { - self.scrollDirection = UICollectionViewScrollDirectionHorizontal; - self.minimumInteritemSpacing = 0; - self.minimumLineSpacing = 0; - self.itemSize = CGSizeMake(1, 1); - self.sectionInset = UIEdgeInsetsZero; - } - return self; -} - -- (void)prepareLayout -{ - [super prepareLayout]; - - CGFloat rowHeight = self.calendar.preferredRowHeight; - - if (!self.calendar.floatingMode) { - - self.headerReferenceSize = CGSizeZero; - - CGFloat padding = self.calendar.preferredPadding; - if (self.scrollDirection == UICollectionViewScrollDirectionHorizontal) { - padding = FSCalendarFloor(padding); - rowHeight = FSCalendarFloor(rowHeight*2)*0.5; // Round to nearest multiple of 0.5. e.g. (16.8->16.5),(16.2->16.0) - } - self.sectionInset = UIEdgeInsetsMake(padding, 0, padding, 0); - switch (self.calendar.scope) { - - case FSCalendarScopeMonth: { - - CGSize itemSize = CGSizeMake( - self.collectionView.fs_width/7.0-(self.scrollDirection == UICollectionViewScrollDirectionVertical)*0.1, - rowHeight - ); - self.itemSize = itemSize; - - break; - } - case FSCalendarScopeWeek: { - - CGSize itemSize = CGSizeMake(self.collectionView.fs_width/7.0, rowHeight); - self.itemSize = itemSize; - - break; - - } - - } - } else { - - CGFloat headerHeight = self.calendar.preferredWeekdayHeight*1.5+self.calendar.preferredHeaderHeight; - self.headerReferenceSize = CGSizeMake(self.collectionView.fs_width, headerHeight); - - CGSize itemSize = CGSizeMake( - self.collectionView.fs_width/7-(self.scrollDirection == UICollectionViewScrollDirectionVertical)*0.1, - rowHeight - ); - self.itemSize = itemSize; - - self.sectionInset = UIEdgeInsetsZero; - - } - -} - -@end diff --git a/FSCalendar/FSCalendarStickyHeader.m b/FSCalendar/FSCalendarStickyHeader.m index 6aeb71b9..4cd11e0a 100644 --- a/FSCalendar/FSCalendarStickyHeader.m +++ b/FSCalendar/FSCalendarStickyHeader.m @@ -15,7 +15,7 @@ @interface FSCalendarStickyHeader () @property (weak , nonatomic) UIView *contentView; -@property (weak , nonatomic) UIView *separator; +@property (weak , nonatomic) UIView *bottomBorder; @property (weak , nonatomic) UIImageView *weekdayView; @property (assign, nonatomic) BOOL needsAdjustingViewFrame; @@ -46,9 +46,9 @@ - (instancetype)initWithFrame:(CGRect)frame self.titleLabel = label; view = [[UIView alloc] initWithFrame:CGRectZero]; - view.backgroundColor = [[UIColor lightGrayColor] colorWithAlphaComponent:0.25]; + view.backgroundColor = FSCalendarStandardLineColor; [_contentView addSubview:view]; - self.separator = view; + self.bottomBorder = view; NSMutableArray *weekdayLabels = [NSMutableArray arrayWithCapacity:7]; for (int i = 0; i < 7; i++) { @@ -82,8 +82,8 @@ - (void)layoutSubviews CGFloat titleHeight = [@"1" sizeWithAttributes:@{NSFontAttributeName:_appearance.preferredHeaderTitleFont}].height*1.5 + weekdayMargin*3; - _separator.frame = CGRectMake(0, _contentView.fs_height-weekdayHeight-weekdayMargin*2, _contentView.fs_width, 1.0); - _titleLabel.frame = CGRectMake(0, _separator.fs_bottom-titleHeight-weekdayMargin, titleWidth,titleHeight); + _bottomBorder.frame = CGRectMake(0, _contentView.fs_height-weekdayHeight-weekdayMargin*2, _contentView.fs_width, 1.0); + _titleLabel.frame = CGRectMake(0, _bottomBorder.fs_bottom-titleHeight-weekdayMargin, titleWidth,titleHeight); self.weekdayView.frame = CGRectMake(self.weekdayLabels.firstObject.fs_left, self.weekdayLabels.firstObject.fs_top, self.weekdayLabels.lastObject.fs_right, self.weekdayLabels.firstObject.fs_height); diff --git a/SwiftExample/SwiftExample.xcodeproj/project.pbxproj b/SwiftExample/SwiftExample.xcodeproj/project.pbxproj index 053181fd..aa362574 100644 --- a/SwiftExample/SwiftExample.xcodeproj/project.pbxproj +++ b/SwiftExample/SwiftExample.xcodeproj/project.pbxproj @@ -13,7 +13,7 @@ 303DE6C11DB1CA3A00F43A0F /* FSCalendarConstants.m in Sources */ = {isa = PBXBuildFile; fileRef = 303DE6C01DB1CA3A00F43A0F /* FSCalendarConstants.m */; }; 3055B1C81DA9338C002AFA13 /* FSCalendarExtensions.m in Sources */ = {isa = PBXBuildFile; fileRef = 3055B1C71DA9338C002AFA13 /* FSCalendarExtensions.m */; }; 306DB1461C96700800A10478 /* FSCalendarAnimator.m in Sources */ = {isa = PBXBuildFile; fileRef = 306DB1451C96700800A10478 /* FSCalendarAnimator.m */; }; - 3078A8B11C50C0ED003D33EF /* FSCalendarFlowLayout.m in Sources */ = {isa = PBXBuildFile; fileRef = EEC9C03F1BDCA2D600383A07 /* FSCalendarFlowLayout.m */; }; + 30921AD01DC0F5E000616B57 /* FSCalendarCollectionViewLayout.m in Sources */ = {isa = PBXBuildFile; fileRef = 30921ACF1DC0F5DF00616B57 /* FSCalendarCollectionViewLayout.m */; }; 30D458E91DB4E2DB00B163C7 /* LoadViewExampleViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 30D458E81DB4E2DB00B163C7 /* LoadViewExampleViewController.swift */; }; EE0954AD1B97DDE0007F6964 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE0954AC1B97DDE0007F6964 /* AppDelegate.swift */; }; EE0954AF1B97DDE0007F6964 /* InterfaceBuilderViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE0954AE1B97DDE0007F6964 /* InterfaceBuilderViewController.swift */; }; @@ -51,6 +51,8 @@ 3055B1C71DA9338C002AFA13 /* FSCalendarExtensions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FSCalendarExtensions.m; sourceTree = ""; }; 306DB1441C96700800A10478 /* FSCalendarAnimator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FSCalendarAnimator.h; sourceTree = ""; }; 306DB1451C96700800A10478 /* FSCalendarAnimator.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FSCalendarAnimator.m; sourceTree = ""; }; + 30921ACE1DC0F5DF00616B57 /* FSCalendarCollectionViewLayout.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FSCalendarCollectionViewLayout.h; sourceTree = ""; }; + 30921ACF1DC0F5DF00616B57 /* FSCalendarCollectionViewLayout.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FSCalendarCollectionViewLayout.m; sourceTree = ""; }; 30D458E81DB4E2DB00B163C7 /* LoadViewExampleViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LoadViewExampleViewController.swift; sourceTree = ""; }; EE0954A71B97DDE0007F6964 /* SwiftExample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = SwiftExample.app; sourceTree = BUILT_PRODUCTS_DIR; }; EE0954AB1B97DDE0007F6964 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; @@ -77,8 +79,6 @@ EE2B62821BB6D7FE00ACB430 /* FSCalendarStickyHeader.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FSCalendarStickyHeader.m; sourceTree = ""; }; EEC9C03C1BDCA2D600383A07 /* FSCalendarCollectionView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FSCalendarCollectionView.h; sourceTree = ""; }; EEC9C03D1BDCA2D600383A07 /* FSCalendarCollectionView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FSCalendarCollectionView.m; sourceTree = ""; }; - EEC9C03E1BDCA2D600383A07 /* FSCalendarFlowLayout.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FSCalendarFlowLayout.h; sourceTree = ""; }; - EEC9C03F1BDCA2D600383A07 /* FSCalendarFlowLayout.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FSCalendarFlowLayout.m; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -174,8 +174,8 @@ 303DE6C01DB1CA3A00F43A0F /* FSCalendarConstants.m */, EEC9C03C1BDCA2D600383A07 /* FSCalendarCollectionView.h */, EEC9C03D1BDCA2D600383A07 /* FSCalendarCollectionView.m */, - EEC9C03E1BDCA2D600383A07 /* FSCalendarFlowLayout.h */, - EEC9C03F1BDCA2D600383A07 /* FSCalendarFlowLayout.m */, + 30921ACE1DC0F5DF00616B57 /* FSCalendarCollectionViewLayout.h */, + 30921ACF1DC0F5DF00616B57 /* FSCalendarCollectionViewLayout.m */, 306DB1441C96700800A10478 /* FSCalendarAnimator.h */, 306DB1451C96700800A10478 /* FSCalendarAnimator.m */, EE0954D81B97DDF4007F6964 /* FSCalendarHeader.h */, @@ -301,12 +301,12 @@ 303DE6C11DB1CA3A00F43A0F /* FSCalendarConstants.m in Sources */, EEC9C0401BDCA2D600383A07 /* FSCalendarCollectionView.m in Sources */, EE0954E81B97DDF4007F6964 /* FSCalendarHeader.m in Sources */, + 30921AD01DC0F5E000616B57 /* FSCalendarCollectionViewLayout.m in Sources */, 303478391DB520C8007BBD2E /* TableViewController.swift in Sources */, EE2B62831BB6D7FE00ACB430 /* FSCalendarStickyHeader.m in Sources */, 306DB1461C96700800A10478 /* FSCalendarAnimator.m in Sources */, EE0954E41B97DDF4007F6964 /* FSCalendar.m in Sources */, 3055B1C81DA9338C002AFA13 /* FSCalendarExtensions.m in Sources */, - 3078A8B11C50C0ED003D33EF /* FSCalendarFlowLayout.m in Sources */, 30D458E91DB4E2DB00B163C7 /* LoadViewExampleViewController.swift in Sources */, EE0954E51B97DDF4007F6964 /* FSCalendarAppearance.m in Sources */, EE0954AD1B97DDE0007F6964 /* AppDelegate.swift in Sources */, diff --git a/TodayExtensionExample/TodayExtensionExample.xcodeproj/project.pbxproj b/TodayExtensionExample/TodayExtensionExample.xcodeproj/project.pbxproj index 7ed7f650..d4516a23 100644 --- a/TodayExtensionExample/TodayExtensionExample.xcodeproj/project.pbxproj +++ b/TodayExtensionExample/TodayExtensionExample.xcodeproj/project.pbxproj @@ -13,12 +13,12 @@ 300036F11D9252CB00C795DE /* FSCalendarAppearance.m in Sources */ = {isa = PBXBuildFile; fileRef = 300036D51D9252CB00C795DE /* FSCalendarAppearance.m */; }; 300036F21D9252CB00C795DE /* FSCalendarCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 300036D71D9252CB00C795DE /* FSCalendarCell.m */; }; 300036F31D9252CB00C795DE /* FSCalendarCollectionView.m in Sources */ = {isa = PBXBuildFile; fileRef = 300036D91D9252CB00C795DE /* FSCalendarCollectionView.m */; }; - 300036F61D9252CB00C795DE /* FSCalendarFlowLayout.m in Sources */ = {isa = PBXBuildFile; fileRef = 300036E01D9252CB00C795DE /* FSCalendarFlowLayout.m */; }; 300036F71D9252CB00C795DE /* FSCalendarHeader.m in Sources */ = {isa = PBXBuildFile; fileRef = 300036E21D9252CB00C795DE /* FSCalendarHeader.m */; }; 300036F81D9252CB00C795DE /* FSCalendarScopeHandle.m in Sources */ = {isa = PBXBuildFile; fileRef = 300036E41D9252CB00C795DE /* FSCalendarScopeHandle.m */; }; 300036F91D9252CB00C795DE /* FSCalendarStickyHeader.m in Sources */ = {isa = PBXBuildFile; fileRef = 300036E61D9252CB00C795DE /* FSCalendarStickyHeader.m */; }; 300036FA1D9252CB00C795DE /* Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 300036E71D9252CB00C795DE /* Info.plist */; }; 3055B1CE1DA933D0002AFA13 /* FSCalendarExtensions.m in Sources */ = {isa = PBXBuildFile; fileRef = 3055B1CD1DA933D0002AFA13 /* FSCalendarExtensions.m */; }; + 30623F6D1DC1F45600FA31B3 /* FSCalendarCollectionViewLayout.m in Sources */ = {isa = PBXBuildFile; fileRef = 30623F6C1DC1F45600FA31B3 /* FSCalendarCollectionViewLayout.m */; }; 3091756F1D7EBD4100BBEB79 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 3091756E1D7EBD4100BBEB79 /* main.m */; }; 309175721D7EBD4100BBEB79 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 309175711D7EBD4100BBEB79 /* AppDelegate.m */; }; 309175751D7EBD4100BBEB79 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 309175741D7EBD4100BBEB79 /* ViewController.m */; }; @@ -70,8 +70,6 @@ 300036D81D9252CB00C795DE /* FSCalendarCollectionView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FSCalendarCollectionView.h; sourceTree = ""; }; 300036D91D9252CB00C795DE /* FSCalendarCollectionView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FSCalendarCollectionView.m; sourceTree = ""; }; 300036DC1D9252CB00C795DE /* FSCalendarDynamicHeader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FSCalendarDynamicHeader.h; sourceTree = ""; }; - 300036DF1D9252CB00C795DE /* FSCalendarFlowLayout.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FSCalendarFlowLayout.h; sourceTree = ""; }; - 300036E01D9252CB00C795DE /* FSCalendarFlowLayout.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FSCalendarFlowLayout.m; sourceTree = ""; }; 300036E11D9252CB00C795DE /* FSCalendarHeader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FSCalendarHeader.h; sourceTree = ""; }; 300036E21D9252CB00C795DE /* FSCalendarHeader.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FSCalendarHeader.m; sourceTree = ""; }; 300036E31D9252CB00C795DE /* FSCalendarScopeHandle.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FSCalendarScopeHandle.h; sourceTree = ""; }; @@ -81,6 +79,8 @@ 300036E71D9252CB00C795DE /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 3055B1CC1DA933D0002AFA13 /* FSCalendarExtensions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FSCalendarExtensions.h; sourceTree = ""; }; 3055B1CD1DA933D0002AFA13 /* FSCalendarExtensions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FSCalendarExtensions.m; sourceTree = ""; }; + 30623F6B1DC1F45600FA31B3 /* FSCalendarCollectionViewLayout.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FSCalendarCollectionViewLayout.h; sourceTree = ""; }; + 30623F6C1DC1F45600FA31B3 /* FSCalendarCollectionViewLayout.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FSCalendarCollectionViewLayout.m; sourceTree = ""; }; 3091756A1D7EBD4100BBEB79 /* TodayExtensionExample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = TodayExtensionExample.app; sourceTree = BUILT_PRODUCTS_DIR; }; 3091756E1D7EBD4100BBEB79 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 309175701D7EBD4100BBEB79 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; @@ -135,8 +135,8 @@ 300036D81D9252CB00C795DE /* FSCalendarCollectionView.h */, 300036D91D9252CB00C795DE /* FSCalendarCollectionView.m */, 300036DC1D9252CB00C795DE /* FSCalendarDynamicHeader.h */, - 300036DF1D9252CB00C795DE /* FSCalendarFlowLayout.h */, - 300036E01D9252CB00C795DE /* FSCalendarFlowLayout.m */, + 30623F6B1DC1F45600FA31B3 /* FSCalendarCollectionViewLayout.h */, + 30623F6C1DC1F45600FA31B3 /* FSCalendarCollectionViewLayout.m */, 300036E11D9252CB00C795DE /* FSCalendarHeader.h */, 300036E21D9252CB00C795DE /* FSCalendarHeader.m */, 300036E31D9252CB00C795DE /* FSCalendarScopeHandle.h */, @@ -333,10 +333,10 @@ files = ( 300036F91D9252CB00C795DE /* FSCalendarStickyHeader.m in Sources */, 30A33A0E1DB1CA8D0039BEA3 /* FSCalendarConstants.m in Sources */, + 30623F6D1DC1F45600FA31B3 /* FSCalendarCollectionViewLayout.m in Sources */, 300036ED1D9252CB00C795DE /* FSCalendar+Deprecated.m in Sources */, 300036F01D9252CB00C795DE /* FSCalendarAnimator.m in Sources */, 300036F31D9252CB00C795DE /* FSCalendarCollectionView.m in Sources */, - 300036F61D9252CB00C795DE /* FSCalendarFlowLayout.m in Sources */, 300036F71D9252CB00C795DE /* FSCalendarHeader.m in Sources */, 3055B1CE1DA933D0002AFA13 /* FSCalendarExtensions.m in Sources */, 300036F81D9252CB00C795DE /* FSCalendarScopeHandle.m in Sources */, From 1999cde3589aea091b73ac995f98f51e3d2b4006 Mon Sep 17 00:00:00 2001 From: Wenchao Ding Date: Thu, 27 Oct 2016 22:02:12 +0800 Subject: [PATCH 5/5] Replace private extension with NSCalendar category --- FSCalendar/FSCalendar.m | 139 +++++--------------- FSCalendar/FSCalendarAnimator.m | 10 +- FSCalendar/FSCalendarCollectionViewLayout.m | 2 +- FSCalendar/FSCalendarDynamicHeader.h | 7 - FSCalendar/FSCalendarExtensions.h | 12 +- FSCalendar/FSCalendarExtensions.m | 84 ++++++++++++ FSCalendar/FSCalendarHeader.m | 8 +- FSCalendar/FSCalendarScopeHandle.m | 2 +- 8 files changed, 137 insertions(+), 127 deletions(-) diff --git a/FSCalendar/FSCalendar.m b/FSCalendar/FSCalendar.m index 2d45bd2a..9d524bdf 100644 --- a/FSCalendar/FSCalendar.m +++ b/FSCalendar/FSCalendar.m @@ -76,16 +76,6 @@ - (BOOL)boundingRectWillChange:(BOOL)animated; @end -@interface FSCalendar (Private) - -- (NSDate *)beginingOfMonth:(NSDate *)month; -- (NSDate *)endOfMonth:(NSDate *)month; -- (NSDate *)beginingOfWeek:(NSDate *)week; -- (NSDate *)endOfWeek:(NSDate *)week; -- (NSDate *)middleOfWeek:(NSDate *)week; -- (NSInteger)numberOfDatesInMonth:(NSDate *)month; - -@end @interface FSCalendar () { @@ -217,7 +207,7 @@ - (void)initialize _today = [self.gregorian dateBySettingHour:0 minute:0 second:0 ofDate:[NSDate date] options:0]; - _currentPage = [self beginingOfMonth:_today]; + _currentPage = [self.gregorian fs_firstDayOfMonth:_today]; #if TARGET_INTERFACE_BUILDER _minimumDate = [self.gregorian dateByAddingUnit:NSCalendarUnitMonth value:-1 toDate:_today options:0]; @@ -522,16 +512,16 @@ - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView { [self requestBoundingDatesIfNecessary]; if (self.animator.transition == FSCalendarTransitionWeekToMonth) { - NSInteger sections = [self.gregorian components:NSCalendarUnitMonth fromDate:[self beginingOfMonth:self.minimumDate] toDate:self.maximumDate options:0].month + 1; + NSInteger sections = [self.gregorian components:NSCalendarUnitMonth fromDate:[self.gregorian fs_firstDayOfMonth:self.minimumDate] toDate:self.maximumDate options:0].month + 1; return sections; } switch (_scope) { case FSCalendarScopeMonth: { - NSInteger sections = [self.gregorian components:NSCalendarUnitMonth fromDate:[self beginingOfMonth:self.minimumDate] toDate:self.maximumDate options:0].month + 1; + NSInteger sections = [self.gregorian components:NSCalendarUnitMonth fromDate:[self.gregorian fs_firstDayOfMonth:self.minimumDate] toDate:self.maximumDate options:0].month + 1; return sections; } case FSCalendarScopeWeek: { - NSInteger sections = [self.gregorian components:NSCalendarUnitWeekOfYear fromDate:[self beginingOfWeek:self.minimumDate] toDate:self.maximumDate options:0].weekOfYear + 1; + NSInteger sections = [self.gregorian components:NSCalendarUnitWeekOfYear fromDate:[self.gregorian fs_firstDayOfWeek:self.minimumDate] toDate:self.maximumDate options:0].weekOfYear + 1; return sections; } } @@ -552,7 +542,7 @@ - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSe } } } else { - NSDate *currentPage = [self.gregorian dateByAddingUnit:NSCalendarUnitMonth value:section toDate:[self beginingOfMonth:_minimumDate] options:0]; + NSDate *currentPage = [self.gregorian dateByAddingUnit:NSCalendarUnitMonth value:section toDate:[self.gregorian fs_firstDayOfMonth:_minimumDate] options:0]; NSInteger numberOfRows = [self numberOfRowsInMonth:currentPage]; return numberOfRows * 7; } @@ -572,7 +562,7 @@ - (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView if ([kind isEqualToString:UICollectionElementKindSectionHeader]) { FSCalendarStickyHeader *stickyHeader = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"header" forIndexPath:indexPath]; stickyHeader.calendar = self; - stickyHeader.month = [self.gregorian dateByAddingUnit:NSCalendarUnitMonth value:indexPath.section toDate:[self beginingOfMonth:_minimumDate] options:0]; + stickyHeader.month = [self.gregorian dateByAddingUnit:NSCalendarUnitMonth value:indexPath.section toDate:[self.gregorian fs_firstDayOfMonth:_minimumDate] options:0]; [stickyHeader setNeedsLayout]; NSArray *allKeys = [_stickyHeaderMapTable.dictionaryRepresentation allKeysForObject:stickyHeader]; if (allKeys.count) { @@ -688,7 +678,7 @@ - (void)scrollViewDidScroll:(UIScrollView *)scrollView CGPoint significantPoint = CGPointMake(_collectionView.fs_width*0.5,MIN(self.preferredRowHeight*2.75, _collectionView.fs_height*0.5)+_collectionView.contentOffset.y); NSIndexPath *significantIndexPath = [_collectionView indexPathForItemAtPoint:significantPoint]; if (significantIndexPath) { - currentPage = [self.gregorian dateByAddingUnit:NSCalendarUnitMonth value:significantIndexPath.section toDate:[self beginingOfMonth:_minimumDate] options:0]; + currentPage = [self.gregorian dateByAddingUnit:NSCalendarUnitMonth value:significantIndexPath.section toDate:[self.gregorian fs_firstDayOfMonth:_minimumDate] options:0]; } else { FSCalendarStickyHeader *significantHeader = [_stickyHeaderMapTable.dictionaryRepresentation.allValues filteredArrayUsingPredicate:[NSPredicate predicateWithBlock:^BOOL(FSCalendarStickyHeader * _Nonnull evaluatedObject, NSDictionary * _Nullable bindings) { return CGRectContainsPoint(evaluatedObject.frame, significantPoint); @@ -744,12 +734,12 @@ - (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoi NSDate *targetPage = nil; switch (_scope) { case FSCalendarScopeMonth: { - NSDate *minimumPage = [self beginingOfMonth:_minimumDate]; + NSDate *minimumPage = [self.gregorian fs_firstDayOfMonth:_minimumDate]; targetPage = [self.gregorian dateByAddingUnit:NSCalendarUnitMonth value:sections toDate:minimumPage options:0]; break; } case FSCalendarScopeWeek: { - NSDate *minimumPage = [self beginingOfWeek:_minimumDate]; + NSDate *minimumPage = [self.gregorian fs_firstDayOfWeek:_minimumDate]; targetPage = [self.gregorian dateByAddingUnit:NSCalendarUnitWeekOfYear value:sections toDate:minimumPage options:0]; break; } @@ -979,8 +969,8 @@ - (void)setOrientation:(FSCalendarOrientation)orientation _preferredPadding = FSCalendarAutomaticDimension; [self.visibleStickyHeaders setValue:@YES forKey:@"needsAdjustingViewFrame"]; [self.visibleStickyHeaders makeObjectsPerformSelector:@selector(setNeedsLayout)]; - [_collectionView.visibleCells setValue:@YES forKey:@"needsAdjustingViewFrame"]; - [_collectionView.visibleCells makeObjectsPerformSelector:@selector(setNeedsLayout)]; + [self.collectionView.visibleCells setValue:@YES forKey:@"needsAdjustingViewFrame"]; + [self.collectionView.visibleCells makeObjectsPerformSelector:@selector(setNeedsLayout)]; [self setNeedsLayout]; } } @@ -1274,13 +1264,13 @@ - (void)scrollToDate:(NSDate *)date animated:(BOOL)animated NSInteger scrollOffset = 0; switch (_scope) { case FSCalendarScopeMonth: { - FSCalendarAssertDateInBounds(date,self.gregorian,[self beginingOfMonth:self.minimumDate],[self endOfMonth:self.maximumDate]); - scrollOffset = [self.gregorian components:NSCalendarUnitMonth fromDate:[self beginingOfMonth:self.minimumDate] toDate:date options:0].month; + FSCalendarAssertDateInBounds(date,self.gregorian,[self.gregorian fs_firstDayOfMonth:self.minimumDate],[self.gregorian fs_lastDayOfMonth:self.maximumDate]); + scrollOffset = [self.gregorian components:NSCalendarUnitMonth fromDate:[self.gregorian fs_firstDayOfMonth:self.minimumDate] toDate:date options:0].month; break; } case FSCalendarScopeWeek: { - FSCalendarAssertDateInBounds(date,self.gregorian,[self beginingOfWeek:self.minimumDate],[self endOfWeek:self.maximumDate]); - scrollOffset = [self.gregorian components:NSCalendarUnitWeekOfYear fromDate:[self beginingOfWeek:self.minimumDate] toDate:date options:0].weekOfYear; + FSCalendarAssertDateInBounds(date,self.gregorian,[self.gregorian fs_firstDayOfWeek:self.minimumDate],[self.gregorian fs_lastDayOfWeek:self.maximumDate]); + scrollOffset = [self.gregorian components:NSCalendarUnitWeekOfYear fromDate:[self.gregorian fs_firstDayOfWeek:self.minimumDate] toDate:date options:0].weekOfYear; break; } } @@ -1328,13 +1318,13 @@ - (void)scrollToPageForDate:(NSDate *)date animated:(BOOL)animated NSDate *lastPage = _currentPage; switch (_scope) { case FSCalendarScopeMonth: { - FSCalendarAssertDateInBounds(date, self.gregorian, [self beginingOfMonth:self.minimumDate], [self endOfMonth:self.maximumDate]); - _currentPage = [self beginingOfMonth:date]; + FSCalendarAssertDateInBounds(date, self.gregorian, [self.gregorian fs_firstDayOfMonth:self.minimumDate], [self.gregorian fs_lastDayOfMonth:self.maximumDate]); + _currentPage = [self.gregorian fs_firstDayOfMonth:date]; break; } case FSCalendarScopeWeek: { - FSCalendarAssertDateInBounds(date, self.gregorian, [self beginingOfWeek:self.minimumDate], [self endOfWeek:self.maximumDate]); - _currentPage = [self beginingOfWeek:date]; + FSCalendarAssertDateInBounds(date, self.gregorian, [self.gregorian fs_firstDayOfWeek:self.minimumDate], [self.gregorian fs_lastDayOfWeek:self.maximumDate]); + _currentPage = [self.gregorian fs_firstDayOfWeek:date]; break; } } @@ -1350,7 +1340,7 @@ - (void)scrollToPageForDate:(NSDate *)date animated:(BOOL)animated } [self scrollToDate:_currentPage animated:animated]; } else { - [self scrollToDate:[self beginingOfMonth:date] animated:animated]; + [self scrollToDate:[self.gregorian fs_firstDayOfMonth:date] animated:animated]; } } @@ -1359,7 +1349,7 @@ - (NSDate *)dateForIndexPath:(NSIndexPath *)indexPath scope:(FSCalendarScope)sco if (!indexPath) return nil; switch (scope) { case FSCalendarScopeMonth: { - NSDate *currentPage = [self.gregorian dateByAddingUnit:NSCalendarUnitMonth value:indexPath.section toDate:[self beginingOfMonth:_minimumDate] options:0]; + NSDate *currentPage = [self.gregorian dateByAddingUnit:NSCalendarUnitMonth value:indexPath.section toDate:[self.gregorian fs_firstDayOfMonth:_minimumDate] options:0]; NSInteger numberOfHeadPlaceholders = [self numberOfHeadPlaceholdersForMonth:currentPage]; NSDate *firstDateOfPage = [self.gregorian dateByAddingUnit:NSCalendarUnitDay value:-numberOfHeadPlaceholders toDate:currentPage options:0]; switch (_collectionViewLayout.scrollDirection) { @@ -1379,7 +1369,7 @@ - (NSDate *)dateForIndexPath:(NSIndexPath *)indexPath scope:(FSCalendarScope)sco break; } case FSCalendarScopeWeek: { - NSDate *currentPage = [self.gregorian dateByAddingUnit:NSCalendarUnitWeekOfYear value:indexPath.section toDate:[self beginingOfWeek:_minimumDate] options:0]; + NSDate *currentPage = [self.gregorian dateByAddingUnit:NSCalendarUnitWeekOfYear value:indexPath.section toDate:[self.gregorian fs_firstDayOfWeek:_minimumDate] options:0]; NSDate *date = [self.gregorian dateByAddingUnit:NSCalendarUnitDay value:indexPath.item toDate:currentPage options:0]; return date; @@ -1403,8 +1393,8 @@ - (NSIndexPath *)indexPathForDate:(NSDate *)date scope:(FSCalendarScope)scope NSInteger section = 0; switch (scope) { case FSCalendarScopeMonth: { - section = [self.gregorian components:NSCalendarUnitMonth fromDate:[self beginingOfMonth:self.minimumDate] toDate:date options:0].month; - NSDate *firstDayOfMonth = [self beginingOfMonth:date]; + section = [self.gregorian components:NSCalendarUnitMonth fromDate:[self.gregorian fs_firstDayOfMonth:self.minimumDate] toDate:date options:0].month; + NSDate *firstDayOfMonth = [self.gregorian fs_firstDayOfMonth:date]; NSInteger numberOfHeadPlaceholders = [self numberOfHeadPlaceholdersForMonth:firstDayOfMonth]; NSDate *firstDateOfPage = [self.gregorian dateByAddingUnit:NSCalendarUnitDay value:-numberOfHeadPlaceholders toDate:firstDayOfMonth options:0]; switch (_collectionViewLayout.scrollDirection) { @@ -1423,7 +1413,7 @@ - (NSIndexPath *)indexPathForDate:(NSDate *)date scope:(FSCalendarScope)scope break; } case FSCalendarScopeWeek: { - section = [self.gregorian components:NSCalendarUnitWeekOfYear fromDate:[self beginingOfWeek:self.minimumDate] toDate:date options:0].weekOfYear; + section = [self.gregorian components:NSCalendarUnitWeekOfYear fromDate:[self.gregorian fs_firstDayOfWeek:self.minimumDate] toDate:date options:0].weekOfYear; item = (([self.gregorian component:NSCalendarUnitWeekday fromDate:date] - _firstWeekday) + 7) % 7; break; } @@ -1449,18 +1439,18 @@ - (BOOL)isPageInRange:(NSDate *)page BOOL flag = YES; switch (self.scope) { case FSCalendarScopeMonth: { - NSDateComponents *c1 = [self.gregorian components:NSCalendarUnitDay fromDate:[self beginingOfMonth:self.minimumDate] toDate:page options:0]; + NSDateComponents *c1 = [self.gregorian components:NSCalendarUnitDay fromDate:[self.gregorian fs_firstDayOfMonth:self.minimumDate] toDate:page options:0]; flag &= (c1.day>=0); if (!flag) break; - NSDateComponents *c2 = [self.gregorian components:NSCalendarUnitDay fromDate:page toDate:[self endOfMonth:self.maximumDate] options:0]; + NSDateComponents *c2 = [self.gregorian components:NSCalendarUnitDay fromDate:page toDate:[self.gregorian fs_lastDayOfMonth:self.maximumDate] options:0]; flag &= (c2.day>=0); break; } case FSCalendarScopeWeek: { - NSDateComponents *c1 = [self.gregorian components:NSCalendarUnitDay fromDate:[self beginingOfWeek:self.minimumDate] toDate:page options:0]; + NSDateComponents *c1 = [self.gregorian components:NSCalendarUnitDay fromDate:[self.gregorian fs_firstDayOfWeek:self.minimumDate] toDate:page options:0]; flag &= (c1.day>=0); if (!flag) break; - NSDateComponents *c2 = [self.gregorian components:NSCalendarUnitDay fromDate:page toDate:[self endOfWeek:self.maximumDate] options:0]; + NSDateComponents *c2 = [self.gregorian components:NSCalendarUnitDay fromDate:page toDate:[self.gregorian fs_lastDayOfWeek:self.maximumDate] options:0]; flag &= (c2.day>=0); break; } @@ -1665,7 +1655,7 @@ - (void)reloadDataForCell:(FSCalendarCell *)cell atIndexPath:(NSIndexPath *)inde cell.dateIsToday = self.today?[self.gregorian isDate:cell.date inSameDayAsDate:self.today]:NO; switch (_scope) { case FSCalendarScopeMonth: { - NSDate *firstPage = [self beginingOfMonth:_minimumDate]; + NSDate *firstPage = [self.gregorian fs_firstDayOfMonth:_minimumDate]; NSDate *month = [self.gregorian dateByAddingUnit:NSCalendarUnitMonth value:indexPath.section toDate:firstPage options:0]; cell.month = month; cell.dateIsPlaceholder = ![self.gregorian isDate:cell.date equalToDate:month toUnitGranularity:NSCalendarUnitMonth] || ![self isDateInRange:cell.date]; @@ -1825,9 +1815,9 @@ - (NSInteger)numberOfRowsInMonth:(NSDate *)month { if (!month) return 0; if (self.placeholderType == FSCalendarPlaceholderTypeFillSixRows) return 6; - NSDate *firstDayOfMonth = [self beginingOfMonth:month]; + NSDate *firstDayOfMonth = [self.gregorian fs_firstDayOfMonth:month]; NSInteger weekdayOfFirstDay = [self.gregorian component:NSCalendarUnitWeekday fromDate:firstDayOfMonth]; - NSInteger numberOfDaysInMonth = [self numberOfDatesInMonth:month]; + NSInteger numberOfDaysInMonth = [self.gregorian fs_numberOfDaysInMonth:month]; NSInteger numberOfPlaceholdersForPrev = ((weekdayOfFirstDay - self.firstWeekday) + 7) % 7; NSInteger headDayCount = numberOfDaysInMonth + numberOfPlaceholdersForPrev; NSInteger numberOfRows = (headDayCount/7) + (headDayCount%7>0); @@ -2178,71 +2168,6 @@ - (void)requestBoundingDatesIfNecessary } } -- (NSDate *)beginingOfMonth:(NSDate *)month -{ - if (!month) return nil; - NSDateComponents *components = [self.gregorian components:NSCalendarUnitYear|NSCalendarUnitMonth|NSCalendarUnitDay|NSCalendarUnitHour fromDate:month]; - components.day = 1; - return [self.gregorian dateFromComponents:components]; -} - -- (NSDate *)endOfMonth:(NSDate *)month -{ - if (!month) return nil; - NSDateComponents *components = [self.gregorian components:NSCalendarUnitYear|NSCalendarUnitMonth|NSCalendarUnitDay|NSCalendarUnitHour fromDate:month]; - components.month++; - components.day = 0; - return [self.gregorian dateFromComponents:components]; -} - -- (NSDate *)beginingOfWeek:(NSDate *)week -{ - if (!week) return nil; - NSDateComponents *weekdayComponents = [self.gregorian components:NSCalendarUnitWeekday fromDate:week]; - NSDateComponents *components = self.components; - components.day = - (weekdayComponents.weekday - self.gregorian.firstWeekday); - components.day = (components.day-7) % 7; - NSDate *beginningOfWeek = [self.gregorian dateByAddingComponents:components toDate:week options:0]; - beginningOfWeek = [self.gregorian dateBySettingHour:0 minute:0 second:0 ofDate:beginningOfWeek options:0]; - components.day = NSIntegerMax; - return beginningOfWeek; -} - -- (NSDate *)endOfWeek:(NSDate *)week -{ - if (!week) return nil; - NSDateComponents *weekdayComponents = [self.gregorian components:NSCalendarUnitWeekday fromDate:week]; - NSDateComponents *components = self.components; - components.day = - (weekdayComponents.weekday - self.gregorian.firstWeekday); - components.day = (components.day-7) % 7 + 6; - NSDate *endOfWeek = [self.gregorian dateByAddingComponents:components toDate:week options:0]; - endOfWeek = [self.gregorian dateBySettingHour:0 minute:0 second:0 ofDate:endOfWeek options:0]; - components.day = NSIntegerMax; - return endOfWeek; -} - -- (NSDate *)middleOfWeek:(NSDate *)week -{ - if (!week) return nil; - NSDateComponents *weekdayComponents = [self.gregorian components:NSCalendarUnitWeekday fromDate:week]; - NSDateComponents *componentsToSubtract = self.components; - componentsToSubtract.day = - (weekdayComponents.weekday - self.gregorian.firstWeekday) + 3; - NSDate *middleOfWeek = [self.gregorian dateByAddingComponents:componentsToSubtract toDate:week options:0]; - NSDateComponents *components = [self.gregorian components:NSCalendarUnitYear|NSCalendarUnitMonth|NSCalendarUnitDay|NSCalendarUnitHour fromDate:middleOfWeek]; - middleOfWeek = [self.gregorian dateFromComponents:components]; - componentsToSubtract.day = NSIntegerMax; - return middleOfWeek; -} - -- (NSInteger)numberOfDatesInMonth:(NSDate *)month -{ - if (!month) return 0; - NSRange days = [self.gregorian rangeOfUnit:NSCalendarUnitDay - inUnit:NSCalendarUnitMonth - forDate:month]; - return days.length; -} - - (void)setIdentifier:(NSString *)identifier { if (![identifier isEqualToString:_gregorian.calendarIdentifier]) { diff --git a/FSCalendar/FSCalendarAnimator.m b/FSCalendar/FSCalendarAnimator.m index 2fffbe52..dde0ff84 100644 --- a/FSCalendar/FSCalendarAnimator.m +++ b/FSCalendar/FSCalendarAnimator.m @@ -416,12 +416,12 @@ - (FSCalendarTransitionAttributes *)transitionAttributes } // Focus begining day of month if (!focusedDate) { - focusedDate = [self.calendar beginingOfMonth:self.calendar.currentPage]; + focusedDate = [self.calendar.gregorian fs_firstDayOfMonth:self.calendar.currentPage]; kCalculateRowNumber } NSDate *currentPage = self.calendar.currentPage; - NSDate *minimumPage = [self.calendar beginingOfMonth:self.calendar.minimumDate]; + NSDate *minimumPage = [self.calendar.gregorian fs_firstDayOfMonth:self.calendar.minimumDate]; NSInteger visibleSection = [self.calendar.gregorian components:NSCalendarUnitMonth fromDate:minimumPage toDate:currentPage options:0].month; NSIndexPath *firstIndexPath = [NSIndexPath indexPathForItem:0 inSection:visibleSection]; NSDate *firstDate = [self.calendar dateForIndexPath:firstIndexPath scope:FSCalendarScopeMonth]; @@ -452,12 +452,12 @@ - (FSCalendarTransitionAttributes *)transitionAttributes } } if (!focusedDate) { - focusedDate = [self.calendar endOfWeek:currentPage]; + focusedDate = [self.calendar.gregorian fs_lastDayOfWeek:currentPage]; } - NSDate *firstDayOfMonth = [self.calendar beginingOfMonth:focusedDate]; + NSDate *firstDayOfMonth = [self.calendar.gregorian fs_firstDayOfMonth:focusedDate]; attributes.focusedDate = focusedDate; - firstDayOfMonth = firstDayOfMonth ?: [self.calendar beginingOfMonth:currentPage]; + firstDayOfMonth = firstDayOfMonth ?: [self.calendar.gregorian fs_firstDayOfMonth:currentPage]; NSInteger numberOfPlaceholdersForPrev = [self.calendar numberOfHeadPlaceholdersForMonth:firstDayOfMonth]; NSDate *firstDateOfPage = [self.calendar.gregorian dateByAddingUnit:NSCalendarUnitDay value:-numberOfPlaceholdersForPrev toDate:firstDayOfMonth options:0]; diff --git a/FSCalendar/FSCalendarCollectionViewLayout.m b/FSCalendar/FSCalendarCollectionViewLayout.m index db98bd87..1d984748 100644 --- a/FSCalendar/FSCalendarCollectionViewLayout.m +++ b/FSCalendar/FSCalendarCollectionViewLayout.m @@ -110,7 +110,7 @@ - (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect return NO; } - NSDate *currentPage = [self.calendar.gregorian dateByAddingUnit:NSCalendarUnitMonth value:evaluatedObject.indexPath.section toDate:[self.calendar beginingOfMonth:self.calendar.minimumDate] options:0]; + NSDate *currentPage = [self.calendar.gregorian dateByAddingUnit:NSCalendarUnitMonth value:evaluatedObject.indexPath.section toDate:[self.calendar.gregorian fs_firstDayOfMonth:self.calendar.minimumDate] options:0]; NSInteger numberOfRows = [self.calendar numberOfRowsInMonth:currentPage]; switch (self.scrollDirection) { diff --git a/FSCalendar/FSCalendarDynamicHeader.h b/FSCalendar/FSCalendarDynamicHeader.h index d543bf18..8c24a8fa 100644 --- a/FSCalendar/FSCalendarDynamicHeader.h +++ b/FSCalendar/FSCalendarDynamicHeader.h @@ -65,13 +65,6 @@ - (NSInteger)numberOfHeadPlaceholdersForMonth:(NSDate *)month; - (NSInteger)numberOfRowsInMonth:(NSDate *)month; -- (NSDate *)beginingOfMonth:(NSDate *)month; -- (NSDate *)endOfMonth:(NSDate *)month; -- (NSDate *)beginingOfWeek:(NSDate *)week; -- (NSDate *)endOfWeek:(NSDate *)week; -- (NSDate *)middleOfWeek:(NSDate *)week; -- (NSInteger)numberOfDatesInMonth:(NSDate *)month; - - (CGSize)sizeThatFits:(CGSize)size scope:(FSCalendarScope)scope; @end diff --git a/FSCalendar/FSCalendarExtensions.h b/FSCalendar/FSCalendarExtensions.h index 1c6920cb..ab9923e2 100644 --- a/FSCalendar/FSCalendarExtensions.h +++ b/FSCalendar/FSCalendarExtensions.h @@ -11,7 +11,6 @@ NS_ASSUME_NONNULL_BEGIN - @interface UIView (FSCalendarExtensions) @property (nonatomic) CGFloat fs_width; @@ -25,7 +24,6 @@ NS_ASSUME_NONNULL_BEGIN @end - @interface CALayer (FSCalendarExtensions) @property (nonatomic) CGFloat fs_width; @@ -38,6 +36,16 @@ NS_ASSUME_NONNULL_BEGIN @end +@interface NSCalendar (FSCalendarExtensions) + +- (nullable NSDate *)fs_firstDayOfMonth:(NSDate *)month; +- (nullable NSDate *)fs_lastDayOfMonth:(NSDate *)month; +- (nullable NSDate *)fs_firstDayOfWeek:(NSDate *)week; +- (nullable NSDate *)fs_lastDayOfWeek:(NSDate *)week; +- (nullable NSDate *)fs_middleDayOfWeek:(NSDate *)week; +- (NSInteger)fs_numberOfDaysInMonth:(NSDate *)month; + +@end @interface NSObject (FSCalendarExtensions) diff --git a/FSCalendar/FSCalendarExtensions.m b/FSCalendar/FSCalendarExtensions.m index 5bfcd5bd..d1361207 100644 --- a/FSCalendar/FSCalendarExtensions.m +++ b/FSCalendar/FSCalendarExtensions.m @@ -7,6 +7,7 @@ // #import "FSCalendarExtensions.h" +#import @implementation UIView (FSCalendarExtensions) @@ -137,6 +138,89 @@ - (void)setFs_right:(CGFloat)fs_right @end +@interface NSCalendar (FSCalendarExtensionsPrivate) + +@property (readonly, nonatomic) NSDateComponents *fs_privateComponents; + +@end + +@implementation NSCalendar (FSCalendarExtensions) + +- (nullable NSDate *)fs_firstDayOfMonth:(NSDate *)month +{ + if (!month) return nil; + NSDateComponents *components = [self components:NSCalendarUnitYear|NSCalendarUnitMonth|NSCalendarUnitDay|NSCalendarUnitHour fromDate:month]; + components.day = 1; + return [self dateFromComponents:components]; +} + +- (nullable NSDate *)fs_lastDayOfMonth:(NSDate *)month +{ + if (!month) return nil; + NSDateComponents *components = [self components:NSCalendarUnitYear|NSCalendarUnitMonth|NSCalendarUnitDay|NSCalendarUnitHour fromDate:month]; + components.day = 1; + return [self dateFromComponents:components]; +} + +- (nullable NSDate *)fs_firstDayOfWeek:(NSDate *)week +{ + if (!week) return nil; + NSDateComponents *weekdayComponents = [self components:NSCalendarUnitWeekday fromDate:week]; + NSDateComponents *components = self.fs_privateComponents; + components.day = - (weekdayComponents.weekday - self.firstWeekday); + components.day = (components.day-7) % 7; + NSDate *firstDayOfWeek = [self dateByAddingComponents:components toDate:week options:0]; + firstDayOfWeek = [self dateBySettingHour:0 minute:0 second:0 ofDate:firstDayOfWeek options:0]; + components.day = NSIntegerMax; + return firstDayOfWeek; +} + +- (nullable NSDate *)fs_lastDayOfWeek:(NSDate *)week +{ + if (!week) return nil; + NSDateComponents *weekdayComponents = [self components:NSCalendarUnitWeekday fromDate:week]; + NSDateComponents *components = self.fs_privateComponents; + components.day = - (weekdayComponents.weekday - self.firstWeekday); + components.day = (components.day-7) % 7 + 6; + NSDate *lastDayOfWeek = [self dateByAddingComponents:components toDate:week options:0]; + lastDayOfWeek = [self dateBySettingHour:0 minute:0 second:0 ofDate:lastDayOfWeek options:0]; + components.day = NSIntegerMax; + return lastDayOfWeek; +} + +- (nullable NSDate *)fs_middleDayOfWeek:(NSDate *)week +{ + if (!week) return nil; + NSDateComponents *weekdayComponents = [self components:NSCalendarUnitWeekday fromDate:week]; + NSDateComponents *componentsToSubtract = self.fs_privateComponents; + componentsToSubtract.day = - (weekdayComponents.weekday - self.firstWeekday) + 3; + NSDate *middleDayOfWeek = [self dateByAddingComponents:componentsToSubtract toDate:week options:0]; + NSDateComponents *components = [self components:NSCalendarUnitYear|NSCalendarUnitMonth|NSCalendarUnitDay|NSCalendarUnitHour fromDate:middleDayOfWeek]; + middleDayOfWeek = [self dateFromComponents:components]; + componentsToSubtract.day = NSIntegerMax; + return middleDayOfWeek; +} + +- (NSInteger)fs_numberOfDaysInMonth:(NSDate *)month +{ + if (!month) return 0; + NSRange days = [self rangeOfUnit:NSCalendarUnitDay + inUnit:NSCalendarUnitMonth + forDate:month]; + return days.length; +} + +- (NSDateComponents *)fs_privateComponents +{ + NSDateComponents *components = objc_getAssociatedObject(self, _cmd); + if (!components) { + components = [[NSDateComponents alloc] init]; + objc_setAssociatedObject(self, _cmd, components, OBJC_ASSOCIATION_RETAIN_NONATOMIC); + } + return components; +} + +@end @implementation NSObject (FSCalendarExtensions) diff --git a/FSCalendar/FSCalendarHeader.m b/FSCalendar/FSCalendarHeader.m index 3a389d25..1caa6740 100644 --- a/FSCalendar/FSCalendarHeader.m +++ b/FSCalendar/FSCalendarHeader.m @@ -101,13 +101,13 @@ - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSe case FSCalendarScopeMonth: { switch (_scrollDirection) { case UICollectionViewScrollDirectionVertical: { - NSDate *minimumPage = [_calendar beginingOfMonth:_calendar.minimumDate]; + NSDate *minimumPage = [_calendar.gregorian fs_firstDayOfMonth:_calendar.minimumDate]; NSInteger months = [self.calendar.gregorian components:NSCalendarUnitMonth fromDate:minimumPage toDate:self.calendar.maximumDate options:0].month + 1; return months; } case UICollectionViewScrollDirectionHorizontal: { // 2 more pages to prevent scrollView from auto bouncing while push/present to other UIViewController - NSDate *minimumPage = [_calendar beginingOfMonth:_calendar.minimumDate]; + NSDate *minimumPage = [_calendar.gregorian fs_firstDayOfMonth:_calendar.minimumDate]; NSInteger months = [self.calendar.gregorian components:NSCalendarUnitMonth fromDate:minimumPage toDate:self.calendar.maximumDate options:0].month + 1; return months + 2; } @@ -118,7 +118,7 @@ - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSe break; } case FSCalendarScopeWeek: { - NSDate *minimumPage = [_calendar beginingOfMonth:_calendar.minimumDate]; + NSDate *minimumPage = [self.calendar.gregorian fs_firstDayOfMonth:_calendar.minimumDate]; NSInteger weeks = [self.calendar.gregorian components:NSCalendarUnitWeekOfYear fromDate:minimumPage toDate:self.calendar.maximumDate options:0].weekOfYear + 1; return weeks + 2; } @@ -158,7 +158,7 @@ - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cell if ((indexPath.item == 0 || indexPath.item == [collectionView numberOfItemsInSection:0] - 1)) { text = nil; } else { - NSDate *firstPage = [_calendar middleOfWeek:_calendar.minimumDate]; + NSDate *firstPage = [self.calendar.gregorian fs_middleDayOfWeek:self.calendar.minimumDate]; NSDate *date = [self.calendar.gregorian dateByAddingUnit:NSCalendarUnitWeekOfYear value:indexPath.item-1 toDate:firstPage options:0]; text = [_calendar.formatter stringFromDate:date]; } diff --git a/FSCalendar/FSCalendarScopeHandle.m b/FSCalendar/FSCalendarScopeHandle.m index 59ad4aa9..2b58cb60 100644 --- a/FSCalendar/FSCalendarScopeHandle.m +++ b/FSCalendar/FSCalendarScopeHandle.m @@ -33,7 +33,7 @@ - (instancetype)initWithFrame:(CGRect)frame UIView *view; view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 1)]; - view.backgroundColor = FSCalendarStandardSeparatorColor; + view.backgroundColor = FSCalendarStandardLineColor; [self addSubview:view]; self.topBorder = view;