From 9e1bbcc874e7f1cd953d1fea2efccfbba536753d Mon Sep 17 00:00:00 2001 From: f33chobits <=> Date: Thu, 12 Mar 2015 22:42:53 +0800 Subject: [PATCH] Almost there Almost there --- Example/FSCalendar/ViewController.m | 5 + Example/Pods/Pods.xcodeproj/project.pbxproj | 32 --- Pod/Classes/FSCalendar.h | 16 +- Pod/Classes/FSCalendar.m | 124 ++++----- Pod/Classes/FSCalendarCell.h | 12 +- Pod/Classes/FSCalendarCell.m | 70 +++-- Pod/Classes/FSCalendarPage.h | 19 -- Pod/Classes/FSCalendarPage.m | 90 ------- Pod/Classes/FSCalendarUnit.h | 60 ----- Pod/Classes/FSCalendarUnit.m | 269 -------------------- Pod/Classes/UIScrollView+FSExtension.h | 15 -- Pod/Classes/UIScrollView+FSExtension.m | 22 -- 12 files changed, 103 insertions(+), 631 deletions(-) delete mode 100644 Pod/Classes/FSCalendarPage.h delete mode 100644 Pod/Classes/FSCalendarPage.m delete mode 100644 Pod/Classes/FSCalendarUnit.h delete mode 100644 Pod/Classes/FSCalendarUnit.m delete mode 100644 Pod/Classes/UIScrollView+FSExtension.h delete mode 100644 Pod/Classes/UIScrollView+FSExtension.m diff --git a/Example/FSCalendar/ViewController.m b/Example/FSCalendar/ViewController.m index b3cac92..c0781e4 100644 --- a/Example/FSCalendar/ViewController.m +++ b/Example/FSCalendar/ViewController.m @@ -39,6 +39,11 @@ return date.fs_day == 3; } +- (BOOL)calendar:(FSCalendar *)calendar shouldSelectDate:(NSDate *)date +{ + return date.fs_day != 3; +} + - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { if ([segue.destinationViewController isKindOfClass:[CalendarConfigViewController class]]) { diff --git a/Example/Pods/Pods.xcodeproj/project.pbxproj b/Example/Pods/Pods.xcodeproj/project.pbxproj index c586885..f096be1 100644 --- a/Example/Pods/Pods.xcodeproj/project.pbxproj +++ b/Example/Pods/Pods.xcodeproj/project.pbxproj @@ -9,13 +9,9 @@ /* Begin PBXBuildFile section */ 06A6652CAA4F629D09931073 /* FSCalendarHeader.m in Sources */ = {isa = PBXBuildFile; fileRef = 6C018919F1D7CA414C325BFC /* FSCalendarHeader.m */; }; 071F947F788DB55493E50A2E /* SSHolidayManager.h in Headers */ = {isa = PBXBuildFile; fileRef = A304D0502E6431796D499DC3 /* SSHolidayManager.h */; }; - 071F9A0BDACA4DF981DF9631 /* FSCalendarPage.m in Sources */ = {isa = PBXBuildFile; fileRef = 592634D55D346607A4B7530F /* FSCalendarPage.m */; }; 11F41E7A1096E4E39D66DFCA /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 35B8509E1C173A49249A7906 /* Foundation.framework */; }; 12F6658964E837712C3803FB /* SSLunarDateType.h in Headers */ = {isa = PBXBuildFile; fileRef = 00F0C0FCD1CA70EDA715C1AE /* SSLunarDateType.h */; }; - 16EBD1265A482A311FDEDC54 /* FSCalendarUnit.h in Headers */ = {isa = PBXBuildFile; fileRef = 2EDF73DE3D0B3F200CAAD391 /* FSCalendarUnit.h */; }; - 17B97CE5B1F2B5A305814C00 /* FSCalendarUnit.h in Headers */ = {isa = PBXBuildFile; fileRef = 2EDF73DE3D0B3F200CAAD391 /* FSCalendarUnit.h */; }; 18C1EF26B95D008BADCC9847 /* SSHolidayUK.h in Headers */ = {isa = PBXBuildFile; fileRef = A8C4EE2C33268843374F4EBB /* SSHolidayUK.h */; }; - 1C322FAC4C1967E9BE96B04C /* FSCalendarPage.h in Headers */ = {isa = PBXBuildFile; fileRef = 449CB7D957C393F01139A125 /* FSCalendarPage.h */; }; 1F9C81EDDD69987013A25004 /* Pods-Tests-FSCalendar-dummy.m in Sources */ = {isa = PBXBuildFile; fileRef = D7D846EE39698459327BA7CE /* Pods-Tests-FSCalendar-dummy.m */; }; 23E0931FD31D84BDCE7DC34E /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 35B8509E1C173A49249A7906 /* Foundation.framework */; }; 2675E7C82B86822C843112D4 /* SSHolidayChina.h in Headers */ = {isa = PBXBuildFile; fileRef = 1C14C67BD676C075F46E0573 /* SSHolidayChina.h */; }; @@ -26,8 +22,6 @@ 480EABFEA0549DB662F27BD3 /* SSHolidayChina.m in Sources */ = {isa = PBXBuildFile; fileRef = 904EC521130A9C55DA0520FB /* SSHolidayChina.m */; }; 4E172241F33075FD37277FED /* Pods-Tests-dummy.m in Sources */ = {isa = PBXBuildFile; fileRef = 0B7C1171485883250D081419 /* Pods-Tests-dummy.m */; }; 4FD6E939AE65BB0AE03EB217 /* SSHolidayUS.h in Headers */ = {isa = PBXBuildFile; fileRef = 1754C9EE0857D9A893A33EFC /* SSHolidayUS.h */; }; - 5029DA571AA8111F00712B83 /* UIScrollView+FSExtension.h in Headers */ = {isa = PBXBuildFile; fileRef = 5029DA551AA8111F00712B83 /* UIScrollView+FSExtension.h */; }; - 5029DA581AA8111F00712B83 /* UIScrollView+FSExtension.m in Sources */ = {isa = PBXBuildFile; fileRef = 5029DA561AA8111F00712B83 /* UIScrollView+FSExtension.m */; }; 50F20D2F1AB134C40030FC95 /* FSCalendarCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 50F20D2E1AB134C40030FC95 /* FSCalendarCell.m */; }; 50F20D321AB13D250030FC95 /* NSCalendar+FSExtension.m in Sources */ = {isa = PBXBuildFile; fileRef = 50F20D311AB13D250030FC95 /* NSCalendar+FSExtension.m */; }; 54B9A49CD681332E0AC96ACB /* SSHolidayManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 994C4E5A9ADBA9E195ED3178 /* SSHolidayManager.m */; }; @@ -44,7 +38,6 @@ 7FD6EC0DCB562F17F085014F /* FSCalendar.h in Headers */ = {isa = PBXBuildFile; fileRef = 1CF2B5A08202EC5C784DA2EE /* FSCalendar.h */; }; 81453B850A5767ED206A50CC /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 35B8509E1C173A49249A7906 /* Foundation.framework */; }; 8290A25E4832756E4AB387A9 /* NSDate+FSExtension.m in Sources */ = {isa = PBXBuildFile; fileRef = 2AF241AFE2CAC20B7AE30AD0 /* NSDate+FSExtension.m */; }; - 8D08840AFE7738707A1D1D79 /* FSCalendarUnit.m in Sources */ = {isa = PBXBuildFile; fileRef = 13C407A02107C4EC403F85BA /* FSCalendarUnit.m */; }; 8D9C236F15AFFB089BA8F132 /* SSHolidayHK.m in Sources */ = {isa = PBXBuildFile; fileRef = 973ECFD136305A45F20E2665 /* SSHolidayHK.m */; }; 8E39A8CEBC1B31BFFE942FF3 /* SSHolidayCountry.m in Sources */ = {isa = PBXBuildFile; fileRef = D637E97EC834C88D544D9D45 /* SSHolidayCountry.m */; }; 92F2991A9EDC359AE24B21C0 /* Pods-FSCalendar-FSCalendar-dummy.m in Sources */ = {isa = PBXBuildFile; fileRef = BE2713D2C24A98D66173E8BF /* Pods-FSCalendar-FSCalendar-dummy.m */; }; @@ -58,11 +51,8 @@ B85D048D3488F863C61E9E57 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 35B8509E1C173A49249A7906 /* Foundation.framework */; }; BD24A587322F1D47ECB4EEB1 /* FSCalendar.m in Sources */ = {isa = PBXBuildFile; fileRef = 48E27B075EF396D90F887249 /* FSCalendar.m */; }; C308110EA432080E3821342C /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 35B8509E1C173A49249A7906 /* Foundation.framework */; }; - CC4E3BEFD14B1728E4E3E127 /* FSCalendarPage.h in Headers */ = {isa = PBXBuildFile; fileRef = 449CB7D957C393F01139A125 /* FSCalendarPage.h */; }; DAE02600B61F38C745EDAC43 /* UIView+FSExtension.h in Headers */ = {isa = PBXBuildFile; fileRef = 54F8D017A120281736F206D6 /* UIView+FSExtension.h */; }; - DCD6AE8F0F77A803338FC125 /* FSCalendarUnit.m in Sources */ = {isa = PBXBuildFile; fileRef = 13C407A02107C4EC403F85BA /* FSCalendarUnit.m */; }; DD1A8515947C3F266D44D612 /* FSCalendarHeader.m in Sources */ = {isa = PBXBuildFile; fileRef = 6C018919F1D7CA414C325BFC /* FSCalendarHeader.m */; }; - DD36C5F3C8FF9E5EA0FE6004 /* FSCalendarPage.m in Sources */ = {isa = PBXBuildFile; fileRef = 592634D55D346607A4B7530F /* FSCalendarPage.m */; }; DECCCF19B405C73B43677CA3 /* UIView+FSExtension.h in Headers */ = {isa = PBXBuildFile; fileRef = 54F8D017A120281736F206D6 /* UIView+FSExtension.h */; }; DFB579C713790E36D7C15C31 /* Pods-FSCalendar-SSLunarDate-dummy.m in Sources */ = {isa = PBXBuildFile; fileRef = 6B740C0AD40FF01EE97B29B5 /* Pods-FSCalendar-SSLunarDate-dummy.m */; }; DFEE36DBFA9C11110EDB0874 /* UIView+FSExtension.m in Sources */ = {isa = PBXBuildFile; fileRef = 8ABD412B8358CA722FC65E56 /* UIView+FSExtension.m */; }; @@ -102,7 +92,6 @@ 00F0C0FCD1CA70EDA715C1AE /* SSLunarDateType.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; name = SSLunarDateType.h; path = SSLunarDate/SSLunarDateType.h; sourceTree = ""; }; 0B7C1171485883250D081419 /* Pods-Tests-dummy.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; path = "Pods-Tests-dummy.m"; sourceTree = ""; }; 12DE6656C02C82877B52AE19 /* SSHolidayUK.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; name = SSHolidayUK.m; path = SSLunarDate/SSHolidayUK.m; sourceTree = ""; }; - 13C407A02107C4EC403F85BA /* FSCalendarUnit.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; name = FSCalendarUnit.m; path = Pod/Classes/FSCalendarUnit.m; sourceTree = ""; }; 1515A8D384F230ABD6D2E8AE /* SSLunarDateHoliday.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; name = SSLunarDateHoliday.m; path = SSLunarDate/SSLunarDateHoliday.m; sourceTree = ""; }; 16740651091FD25BB28E324F /* Pods-FSCalendar.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; path = "Pods-FSCalendar.debug.xcconfig"; sourceTree = ""; }; 16EDAFB94B2BA2DD22066059 /* Pods-Tests-resources.sh */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.script.sh; path = "Pods-Tests-resources.sh"; sourceTree = ""; }; @@ -114,26 +103,21 @@ 27A7099636D7576544139D5F /* libPods-Tests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-Tests.a"; sourceTree = BUILT_PRODUCTS_DIR; }; 2AF241AFE2CAC20B7AE30AD0 /* NSDate+FSExtension.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; name = "NSDate+FSExtension.m"; path = "Pod/Classes/NSDate+FSExtension.m"; sourceTree = ""; }; 2B12C6207F43172D63955C6E /* Pods-FSCalendar-dummy.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; path = "Pods-FSCalendar-dummy.m"; sourceTree = ""; }; - 2EDF73DE3D0B3F200CAAD391 /* FSCalendarUnit.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; name = FSCalendarUnit.h; path = Pod/Classes/FSCalendarUnit.h; sourceTree = ""; }; 2EF18D48DDB2BCA55B013FFC /* Pods-FSCalendar-environment.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; path = "Pods-FSCalendar-environment.h"; sourceTree = ""; }; 3433CC99CF6A63C2EBFFE6DF /* SSHolidayCountry.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; name = SSHolidayCountry.h; path = SSLunarDate/SSHolidayCountry.h; sourceTree = ""; }; 343E5BCAA0301465938D833F /* SSHolidayTW.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; name = SSHolidayTW.m; path = SSLunarDate/SSHolidayTW.m; sourceTree = ""; }; 3586CA1C73833C4AA181EEF0 /* libLunar.c */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.c; name = libLunar.c; path = SSLunarDate/libLunar.c; sourceTree = ""; }; 35B8509E1C173A49249A7906 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.1.sdk/System/Library/Frameworks/Foundation.framework; sourceTree = DEVELOPER_DIR; }; 37DE376E4BF0702F7CDB24A3 /* SSHolidayCA.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; name = SSHolidayCA.h; path = SSLunarDate/SSHolidayCA.h; sourceTree = ""; }; - 449CB7D957C393F01139A125 /* FSCalendarPage.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; name = FSCalendarPage.h; path = Pod/Classes/FSCalendarPage.h; sourceTree = ""; }; 48E27B075EF396D90F887249 /* FSCalendar.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; name = FSCalendar.m; path = Pod/Classes/FSCalendar.m; sourceTree = ""; }; 4DDEAA50E34ADCF1A1E28256 /* SSHolidayWest.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; name = SSHolidayWest.m; path = SSLunarDate/SSHolidayWest.m; sourceTree = ""; }; 4E33EC3A0C38A7AC4F8FBCB2 /* SSHolidayUS.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; name = SSHolidayUS.m; path = SSLunarDate/SSHolidayUS.m; sourceTree = ""; }; - 5029DA551AA8111F00712B83 /* UIScrollView+FSExtension.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "UIScrollView+FSExtension.h"; path = "Pod/Classes/UIScrollView+FSExtension.h"; sourceTree = ""; }; - 5029DA561AA8111F00712B83 /* UIScrollView+FSExtension.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = "UIScrollView+FSExtension.m"; path = "Pod/Classes/UIScrollView+FSExtension.m"; sourceTree = ""; }; 507253B2398C97027677F2D4 /* Pods-FSCalendar-SSLunarDate-prefix.pch */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; path = "Pods-FSCalendar-SSLunarDate-prefix.pch"; sourceTree = ""; }; 50F20D2D1AB134C40030FC95 /* FSCalendarCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = FSCalendarCell.h; path = Pod/Classes/FSCalendarCell.h; sourceTree = ""; }; 50F20D2E1AB134C40030FC95 /* FSCalendarCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = FSCalendarCell.m; path = Pod/Classes/FSCalendarCell.m; sourceTree = ""; }; 50F20D301AB13D250030FC95 /* NSCalendar+FSExtension.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "NSCalendar+FSExtension.h"; path = "Pod/Classes/NSCalendar+FSExtension.h"; sourceTree = ""; }; 50F20D311AB13D250030FC95 /* NSCalendar+FSExtension.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = "NSCalendar+FSExtension.m"; path = "Pod/Classes/NSCalendar+FSExtension.m"; sourceTree = ""; }; 54F8D017A120281736F206D6 /* UIView+FSExtension.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; name = "UIView+FSExtension.h"; path = "Pod/Classes/UIView+FSExtension.h"; sourceTree = ""; }; - 592634D55D346607A4B7530F /* FSCalendarPage.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; name = FSCalendarPage.m; path = Pod/Classes/FSCalendarPage.m; sourceTree = ""; }; 64B1A1249E2764AC2282EB7B /* Pods-Tests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; path = "Pods-Tests.release.xcconfig"; sourceTree = ""; }; 66EDA8E242050E4C1D14E46D /* libPods-FSCalendar-FSCalendar.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-FSCalendar-FSCalendar.a"; sourceTree = BUILT_PRODUCTS_DIR; }; 681D362424AFC41D7697D9F6 /* Pods-FSCalendar-acknowledgements.plist */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.plist.xml; path = "Pods-FSCalendar-acknowledgements.plist"; sourceTree = ""; }; @@ -273,20 +257,14 @@ 48E27B075EF396D90F887249 /* FSCalendar.m */, AB6526D46980E90A1195B163 /* FSCalendarHeader.h */, 6C018919F1D7CA414C325BFC /* FSCalendarHeader.m */, - 449CB7D957C393F01139A125 /* FSCalendarPage.h */, - 592634D55D346607A4B7530F /* FSCalendarPage.m */, 50F20D2D1AB134C40030FC95 /* FSCalendarCell.h */, 50F20D2E1AB134C40030FC95 /* FSCalendarCell.m */, - 2EDF73DE3D0B3F200CAAD391 /* FSCalendarUnit.h */, - 13C407A02107C4EC403F85BA /* FSCalendarUnit.m */, FD7388654A8B1EEC514563FD /* NSDate+FSExtension.h */, 2AF241AFE2CAC20B7AE30AD0 /* NSDate+FSExtension.m */, 54F8D017A120281736F206D6 /* UIView+FSExtension.h */, 8ABD412B8358CA722FC65E56 /* UIView+FSExtension.m */, 50F20D301AB13D250030FC95 /* NSCalendar+FSExtension.h */, 50F20D311AB13D250030FC95 /* NSCalendar+FSExtension.m */, - 5029DA551AA8111F00712B83 /* UIScrollView+FSExtension.h */, - 5029DA561AA8111F00712B83 /* UIScrollView+FSExtension.m */, D2F28E91854D59AA3E5E6865 /* Support Files */, ); name = FSCalendar; @@ -417,9 +395,6 @@ files = ( 5BCDC7864F306CA125751EF5 /* FSCalendar.h in Headers */, B730679168E92DF546DF0AC2 /* FSCalendarHeader.h in Headers */, - 1C322FAC4C1967E9BE96B04C /* FSCalendarPage.h in Headers */, - 5029DA571AA8111F00712B83 /* UIScrollView+FSExtension.h in Headers */, - 17B97CE5B1F2B5A305814C00 /* FSCalendarUnit.h in Headers */, 92F3B29480A568BCB1BC6A5D /* NSDate+FSExtension.h in Headers */, DECCCF19B405C73B43677CA3 /* UIView+FSExtension.h in Headers */, ); @@ -452,8 +427,6 @@ files = ( 7FD6EC0DCB562F17F085014F /* FSCalendar.h in Headers */, 6211B4371C506A7D0BFD7769 /* FSCalendarHeader.h in Headers */, - CC4E3BEFD14B1728E4E3E127 /* FSCalendarPage.h in Headers */, - 16EBD1265A482A311FDEDC54 /* FSCalendarUnit.h in Headers */, 640413C613B42DEAE7C9B33C /* NSDate+FSExtension.h in Headers */, DAE02600B61F38C745EDAC43 /* UIView+FSExtension.h in Headers */, ); @@ -613,11 +586,8 @@ files = ( BD24A587322F1D47ECB4EEB1 /* FSCalendar.m in Sources */, DD1A8515947C3F266D44D612 /* FSCalendarHeader.m in Sources */, - DD36C5F3C8FF9E5EA0FE6004 /* FSCalendarPage.m in Sources */, - DCD6AE8F0F77A803338FC125 /* FSCalendarUnit.m in Sources */, 8290A25E4832756E4AB387A9 /* NSDate+FSExtension.m in Sources */, 92F2991A9EDC359AE24B21C0 /* Pods-FSCalendar-FSCalendar-dummy.m in Sources */, - 5029DA581AA8111F00712B83 /* UIScrollView+FSExtension.m in Sources */, E1581A920AAF15488CF99049 /* UIView+FSExtension.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -638,8 +608,6 @@ files = ( 47E0379FF652099EA8E79A6D /* FSCalendar.m in Sources */, 06A6652CAA4F629D09931073 /* FSCalendarHeader.m in Sources */, - 071F9A0BDACA4DF981DF9631 /* FSCalendarPage.m in Sources */, - 8D08840AFE7738707A1D1D79 /* FSCalendarUnit.m in Sources */, F21881CB63BA2FACEC197427 /* NSDate+FSExtension.m in Sources */, 1F9C81EDDD69987013A25004 /* Pods-Tests-FSCalendar-dummy.m in Sources */, DFEE36DBFA9C11110EDB0874 /* UIView+FSExtension.m in Sources */, diff --git a/Pod/Classes/FSCalendar.h b/Pod/Classes/FSCalendar.h index 60e7799..73f402d 100644 --- a/Pod/Classes/FSCalendar.h +++ b/Pod/Classes/FSCalendar.h @@ -26,6 +26,11 @@ typedef NS_OPTIONS(NSInteger, FSCalendarUnitStyle) { FSCalendarUnitStyleRectangle = 1 }; +typedef NS_OPTIONS(NSInteger, FSCalendarCellStyle) { + FSCalendarCellStyleCircle = 0, + FSCalendarCellStyleRectangle = 1 +}; + typedef NS_OPTIONS(NSInteger, FSCalendarUnitState) { FSCalendarUnitStateNormal = 0, FSCalendarUnitStateSelected = 1, @@ -68,10 +73,11 @@ typedef NS_OPTIONS(NSInteger, FSCalendarUnitState) { @property (assign, nonatomic) CGFloat minDissolvedAlpha UI_APPEARANCE_SELECTOR; @property (assign, nonatomic) FSCalendarUnitStyle unitStyle UI_APPEARANCE_SELECTOR; -@property (strong, nonatomic) UIFont *titleFont UI_APPEARANCE_SELECTOR; -@property (strong, nonatomic) UIFont *subtitleFont UI_APPEARANCE_SELECTOR; -@property (strong, nonatomic) UIFont *weekdayFont UI_APPEARANCE_SELECTOR; -@property (strong, nonatomic) UIFont *headerTitleFont UI_APPEARANCE_SELECTOR; +@property (strong, nonatomic) UIFont *titleFont UI_APPEARANCE_SELECTOR; +@property (strong, nonatomic) UIFont *subtitleFont UI_APPEARANCE_SELECTOR; +@property (strong, nonatomic) UIFont *weekdayFont UI_APPEARANCE_SELECTOR; +@property (strong, nonatomic) UIFont *headerTitleFont UI_APPEARANCE_SELECTOR; +@property (strong, nonatomic) UIColor *eventColor UI_APPEARANCE_SELECTOR; - (void)setWeekdayTextColor:(UIColor *)weekdayTextColor UI_APPEARANCE_SELECTOR; @@ -93,8 +99,6 @@ typedef NS_OPTIONS(NSInteger, FSCalendarUnitState) { - (void)setSelectionColor:(UIColor *)color UI_APPEARANCE_SELECTOR; - (void)setTodayColor:(UIColor *)color UI_APPEARANCE_SELECTOR; -- (void)setEventColor:(UIColor *)color UI_APPEARANCE_SELECTOR; - - (void)reloadData; @end diff --git a/Pod/Classes/FSCalendar.m b/Pod/Classes/FSCalendar.m index c4dbbc4..9a17ec4 100644 --- a/Pod/Classes/FSCalendar.m +++ b/Pod/Classes/FSCalendar.m @@ -6,10 +6,7 @@ // // -#import #import "FSCalendar.h" -#import "FSCalendarPage.h" -#import "FSCalendarUnit.h" #import "FSCalendarHeader.h" #import "UIView+FSExtension.h" #import "NSDate+FSExtension.h" @@ -21,7 +18,7 @@ #define kPink [UIColor colorWithRed:198/255.0 green:51/255.0 blue:42/255.0 alpha:1.0] #define kBlue [UIColor colorWithRed:31/255.0 green:119/255.0 blue:219/255.0 alpha:1.0] -#define kNumberOfPages 61 // From 1970 to 2040 +#define kNumberOfPages (2100-1970+1)*12 // From 1970 to 2100 @interface FSCalendar () @@ -70,10 +67,10 @@ - (void)initialize { - _titleFont = [UIFont systemFontOfSize:16]; - _subtitleFont = [UIFont systemFontOfSize:11]; - _weekdayFont = [UIFont systemFontOfSize:16]; - _headerTitleFont = [UIFont systemFontOfSize:16]; + _titleFont = [UIFont systemFontOfSize:15]; + _subtitleFont = [UIFont systemFontOfSize:10]; + _weekdayFont = [UIFont systemFontOfSize:15]; + _headerTitleFont = [UIFont systemFontOfSize:15]; NSArray *weekSymbols = [[NSCalendar currentCalendar] shortStandaloneWeekdaySymbols]; _weekdays = [NSMutableArray arrayWithCapacity:weekSymbols.count]; @@ -138,14 +135,15 @@ _autoAdjustTitleSize = YES; } -- (void)layoutSubviews +- (void)setBounds:(CGRect)bounds { - [super layoutSubviews]; - CGFloat padding = _collectionView.fs_height * 0.01; + [super setBounds:bounds]; + CGFloat padding = bounds.size.height * 0.01; _collectionView.frame = CGRectMake(0, kWeekHeight, self.fs_width, self.fs_height-kWeekHeight); _collectionViewFlowLayout.itemSize = CGSizeMake(_collectionView.fs_width/7, (_collectionView.fs_height-padding*2)/6); _collectionViewFlowLayout.sectionInset = UIEdgeInsetsMake(padding, 0, padding, 0); + _collectionView.collectionViewLayout = _collectionViewFlowLayout; [_weekdays enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { CGFloat width = self.fs_width/_weekdays.count; CGFloat height = kWeekHeight; @@ -179,13 +177,32 @@ cell.titleLabel.font = _titleFont; cell.subtitleLabel.font = _subtitleFont; } - NSLog(@"%@::%@",@(indexPath.row),@(cell.date.fs_day)); + + cell.hasEvent = [self hasEventForDate:cell.date]; return cell; } - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath { - + FSCalendarCell *cell = (FSCalendarCell *)[collectionView cellForItemAtIndexPath:indexPath]; + if (cell.isPlaceholder) { + + } else { + [cell showAnimation]; + [self didSelectDate:cell.date]; + } +} + +- (BOOL)collectionView:(UICollectionView *)collectionView shouldSelectItemAtIndexPath:(NSIndexPath *)indexPath +{ + FSCalendarCell *cell = (FSCalendarCell *)[collectionView cellForItemAtIndexPath:indexPath]; + return [self shouldSelectDate:cell.date]; +} + +- (void)collectionView:(UICollectionView *)collectionView didDeselectItemAtIndexPath:(NSIndexPath *)indexPath +{ + FSCalendarCell *cell = (FSCalendarCell *)[collectionView cellForItemAtIndexPath:indexPath]; + [cell hideAnimation]; } #pragma mark - Setter & Getter @@ -383,9 +400,12 @@ [self reloadData]; } -- (void)setEventColor:(UIColor *)color +- (void)setEventColor:(UIColor *)eventColor { - + if (![_eventColor isEqual:eventColor]) { + _eventColor = eventColor; + [self reloadData]; + } } - (void)setTitleFont:(UIFont *)font @@ -427,7 +447,7 @@ options:0]; NSDate *firstDayOfMonth = [NSDate fs_dateWithYear:currentMonth.fs_year month:currentMonth.fs_month day:1]; NSInteger numberOfPlaceholdersForPrev = (firstDayOfMonth.fs_weekday - 1) ? : 7; - NSDate *firstDateOfPage = [firstDayOfMonth fs_dateBySubtractingDays:numberOfPlaceholdersForPrev-1]; + NSDate *firstDateOfPage = [firstDayOfMonth fs_dateBySubtractingDays:numberOfPlaceholdersForPrev]; NSDate *dateForRow = [firstDateOfPage fs_dateByAddingDays:7*(indexPath.row%6)+indexPath.row/6]; return dateForRow; } @@ -438,12 +458,13 @@ UIFont *subtitleFont = _subtitleFont; UIFont *headerFont = _headerTitleFont; UIFont *weekdayFont = _weekdayFont; -// if (_autoAdjustTitleSize) { -// titleFont = [titleFont fontWithSize:_scrollView.fs_height/3/6]; -// subtitleFont = [subtitleFont fontWithSize:_scrollView.fs_height/4.3/6]; -// headerFont = titleFont; -// weekdayFont = titleFont; -// } + if (_autoAdjustTitleSize) { + titleFont = [titleFont fontWithSize:_collectionView.fs_height/3/6]; + subtitleFont = [subtitleFont fontWithSize:_collectionView.fs_height/4.3/6]; + headerFont = titleFont; + weekdayFont = titleFont; + } + [_collectionView reloadData]; [_weekdays setValue:weekdayFont forKey:@"font"]; if (_header) { [_header setTitleFont:headerFont]; @@ -485,7 +506,7 @@ { if (_autoAdjustTitleSize != autoAdjustTitleSize) { _autoAdjustTitleSize = autoAdjustTitleSize; - [self setNeedsLayout]; + [self reloadData]; } } @@ -493,65 +514,10 @@ { if (_unitStyle != unitStyle) { _unitStyle = unitStyle; -// [_page0.subviews setValue:@(unitStyle) forKeyPath:@"style"]; -// [_page1.subviews setValue:@(unitStyle) forKeyPath:@"style"]; + [self reloadData]; } } -#pragma mark - Unit DataSource - -- (NSString *)subtitleForUnit:(FSCalendarUnit *)unit -{ - return [self subtitleForDate:unit.date]; -} - -- (BOOL)hasEventForUnit:(FSCalendarUnit *)unit -{ - return [self hasEventForDate:unit.date]; -} - -- (BOOL)unitIsToday:(FSCalendarUnit *)unit -{ - BOOL today = unit.date.fs_year == self.currentDate.fs_year; - today &= unit.date.fs_month == self.currentDate.fs_month; - today &= unit.date.fs_day == self.currentDate.fs_day; - return today; -} - -- (BOOL)unitIsPlaceholder:(FSCalendarUnit *)unit -{ - FSCalendarPage *page = (FSCalendarPage *)unit.superview; - BOOL isPlaceholder = page.date.fs_year != unit.date.fs_year; - isPlaceholder |= page.date.fs_month != unit.date.fs_month; - return isPlaceholder; -} - -- (BOOL)unitIsSelected:(FSCalendarUnit *)unit -{ - if ([self unitIsPlaceholder:unit]) { - return NO; - } - BOOL selected = unit.date.fs_year == self.selectedDate.fs_year; - selected &= unit.date.fs_month == self.selectedDate.fs_month; - selected &= unit.date.fs_day == self.selectedDate.fs_day; - return selected; -} - -- (UIColor *)unitColorForUnit:(FSCalendarUnit *)unit -{ - return _backgroundColors[@(unit.absoluteState)]; -} - -- (UIColor *)titleColorForUnit:(FSCalendarUnit *)unit -{ - return _titleColors[@(unit.absoluteState)]; -} - -- (UIColor *)subtitleColorForUnit:(FSCalendarUnit *)unit -{ - return _subtitleColors[@(unit.absoluteState)]; -} - #pragma mark - Public - (void)reloadData diff --git a/Pod/Classes/FSCalendarCell.h b/Pod/Classes/FSCalendarCell.h index 608d436..cf0a3d6 100644 --- a/Pod/Classes/FSCalendarCell.h +++ b/Pod/Classes/FSCalendarCell.h @@ -7,6 +7,7 @@ // #import +#import "FSCalendar.h" @interface FSCalendarCell : UICollectionViewCell @@ -20,6 +21,15 @@ @property (copy, nonatomic) NSDate *date; @property (copy, nonatomic) NSDate *month; -@property (assign, nonatomic) FSCalendarCellStyle *style; +@property (assign, nonatomic) FSCalendarCellStyle style; +@property (assign, nonatomic) BOOL hasEvent; + +@property (nonatomic, readonly, getter = isPlaceholder) BOOL placeholder; +@property (nonatomic, readonly, getter = isToday) BOOL today; +@property (nonatomic, readonly, getter = isWeekend) BOOL weekend; + +- (void)showAnimation; +- (void)hideAnimation; +- (void)configureCell; @end diff --git a/Pod/Classes/FSCalendarCell.m b/Pod/Classes/FSCalendarCell.m index 063c0fc..2d43ad5 100644 --- a/Pod/Classes/FSCalendarCell.m +++ b/Pod/Classes/FSCalendarCell.m @@ -13,9 +13,6 @@ #define kAnimationDuration 0.15 -#define kTitleHeight self.contentView.fs_height*5.0/6.0 -#define kDiameter MIN(self.contentView.fs_height*5.0/6.0,self.contentView.fs_width) - @interface FSCalendarCell () @property (readonly, nonatomic) UICollectionView *collectionView; @@ -24,18 +21,14 @@ @property (strong, nonatomic) CAShapeLayer *backgroundLayer; @property (strong, nonatomic) CAShapeLayer *eventLayer; -@property (nonatomic, readonly, getter = isPlaceholder) BOOL placeholder; -@property (nonatomic, readonly, getter = isToday) BOOL today; -@property (nonatomic, readonly, getter = isWeekend) BOOL weekend; - - (UIColor *)colorForCurrentStateInDictionary:(NSDictionary *)dictionary; -- (void)configureCell; - @end @implementation FSCalendarCell +#pragma mark - Init and life cycle + - (instancetype)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; @@ -55,45 +48,38 @@ _backgroundLayer = [CAShapeLayer layer]; _backgroundLayer.backgroundColor = [UIColor clearColor].CGColor; _backgroundLayer.hidden = YES; - _backgroundLayer.anchorPoint = CGPointMake(0.5, 0.5); - [self.contentView.layer insertSublayer:_backgroundLayer below:_titleLabel.layer]; + [self.contentView.layer insertSublayer:_backgroundLayer atIndex:0]; _eventLayer = [CAShapeLayer layer]; _eventLayer.backgroundColor = [UIColor clearColor].CGColor; _eventLayer.fillColor = [UIColor cyanColor].CGColor; _eventLayer.path = [UIBezierPath bezierPathWithOvalInRect:_eventLayer.bounds].CGPath; + _eventLayer.hidden = YES; [self.contentView.layer addSublayer:_eventLayer]; } return self; } -- (void)layoutSubviews +- (void)setBounds:(CGRect)bounds { - [super layoutSubviews]; - _backgroundLayer.frame = CGRectMake((self.contentView.fs_width-kDiameter)/2, - (kTitleHeight-kDiameter)/2, - kDiameter, - kDiameter); + [super setBounds:bounds]; + CGFloat titleHeight = bounds.size.height*5.0/6.0; + CGFloat diameter = MIN(bounds.size.height*5.0/6.0,bounds.size.width); + _backgroundLayer.frame = CGRectMake((bounds.size.width-diameter)/2, + (titleHeight-diameter)/2, + diameter, + diameter); CGFloat eventSize = _backgroundLayer.frame.size.height/6.0; _eventLayer.frame = CGRectMake((_backgroundLayer.frame.size.width-eventSize)/2+_backgroundLayer.frame.origin.x, CGRectGetMaxY(_backgroundLayer.frame)+eventSize*0.2, eventSize*0.8, eventSize*0.8); _eventLayer.path = [UIBezierPath bezierPathWithOvalInRect:_eventLayer.bounds].CGPath; + _backgroundLayer.path = _style == FSCalendarCellStyleCircle ? + [UIBezierPath bezierPathWithOvalInRect:_backgroundLayer.bounds].CGPath : + [UIBezierPath bezierPathWithRect:_backgroundLayer.bounds].CGPath; } #pragma mark - Setters -- (void)setSelected:(BOOL)selected -{ - [super setSelected:selected]; - if (!_backgroundLayer.hidden) { - _backgroundLayer.hidden = YES; - } - if (selected) { - [self showAnimation]; - } - [self configureCell]; -} - - (void)setDate:(NSDate *)date { if (![_date isEqualToDate:date]) { @@ -102,7 +88,19 @@ [self configureCell]; } +- (void)setHasEvent:(BOOL)hasEvent +{ + if (_hasEvent != hasEvent) { + _hasEvent = hasEvent; + _eventLayer.hidden = !hasEvent; + } +} +- (void)hideAnimation +{ + _backgroundLayer.hidden = YES; + [self configureCell]; +} #pragma mark - Private @@ -138,24 +136,19 @@ CGFloat subtitleHeight = [_subtitleLabel.text sizeWithAttributes:@{NSFontAttributeName:self.subtitleLabel.font}].height; CGFloat height = titleHeight + subtitleHeight; _titleLabel.frame = CGRectMake(0, - (kTitleHeight-height)*0.5, + (self.contentView.fs_height*5.0/6.0-height)*0.5-1, self.fs_width, titleHeight); _subtitleLabel.frame = CGRectMake(0, - height-subtitleHeight, + height-subtitleHeight-1, self.fs_width, subtitleHeight); - _subtitleLabel.textColor = [self colorForCurrentStateInDictionary:_subtitleColors]; } else { - _titleLabel.frame = CGRectMake(0, 0, self.fs_width, floor(kTitleHeight)); + _titleLabel.frame = CGRectMake(0, 0, self.fs_width, floor(self.contentView.fs_height*5.0/6.0)); _subtitleLabel.hidden = YES; } - if (self.calendar.dataSource && [self.calendar.dataSource respondsToSelector:@selector(calendar:hasEventForDate:)]) { - _eventLayer.hidden = [self.calendar.dataSource calendar:self.calendar hasEventForDate:_date]; - } else { - _eventLayer.hidden = YES; - } + _backgroundLayer.hidden = !self.selected; } - (BOOL)isPlaceholder @@ -192,6 +185,7 @@ group.duration = kAnimationDuration; group.animations = @[zoomOut, zoomIn]; [_backgroundLayer addAnimation:group forKey:@"bounce"]; + [self configureCell]; } - (UIColor *)colorForCurrentStateInDictionary:(NSDictionary *)dictionary diff --git a/Pod/Classes/FSCalendarPage.h b/Pod/Classes/FSCalendarPage.h deleted file mode 100644 index 000875d..0000000 --- a/Pod/Classes/FSCalendarPage.h +++ /dev/null @@ -1,19 +0,0 @@ -// -// FSCalendarViewPage.h -// Pods -// -// Created by Wenchao Ding on 29/1/15. -// -// - -#import - -@class FSCalendar,FSCalendarUnit; - -@interface FSCalendarPage : UIView - -@property (copy, nonatomic) NSDate *date; - -- (FSCalendarUnit *)unitForDate:(NSDate *)date; - -@end diff --git a/Pod/Classes/FSCalendarPage.m b/Pod/Classes/FSCalendarPage.m deleted file mode 100644 index 1ad8fd5..0000000 --- a/Pod/Classes/FSCalendarPage.m +++ /dev/null @@ -1,90 +0,0 @@ -// -// FSCalendarViewPage.m -// Pods -// -// Created by Wenchao Ding on 29/1/15. -// -// - -#import "FSCalendarPage.h" -#import "FSCalendarUnit.h" -#import "NSDate+FSExtension.h" -#import "UIView+FSExtension.h" -#import "FSCalendar.h" - -@interface FSCalendarPage () - -@property (readonly, nonatomic) FSCalendar *calendarView; - -@end - -@implementation FSCalendarPage - -- (instancetype)initWithFrame:(CGRect)frame -{ - self = [super initWithFrame:frame]; - if (self) { - for (int i = 0; i < 42; i++) { - FSCalendarUnit *unit = [[FSCalendarUnit alloc] initWithFrame:CGRectZero]; - [self addSubview:unit]; - } - } - return self; -} - -- (void)setDate:(NSDate *)date -{ - if (![_date isEqualToDate:date]) { - _date = [date copy]; - } - [self updateDateForUnits]; -} - -- (void)layoutSubviews -{ - [super layoutSubviews]; - CGFloat inset = self.fs_height/80; - [self.subviews enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { - NSInteger row = idx / 7; - CGFloat width = self.fs_width/7; - CGFloat height = (self.fs_height-inset*2)/6; - CGFloat top = inset+row * height; - CGFloat left = (idx % 7)*width; - [obj setFrame:CGRectMake(left, top, width, height)]; - }]; -} - -- (void)updateDateForUnits -{ - NSMutableArray *dates = [NSMutableArray arrayWithCapacity:42]; - for (int i = 0; i < _date.fs_numberOfDaysInMonth; i++) { - [dates addObject:[NSDate fs_dateWithYear:_date.fs_year month:_date.fs_month day:i+1]]; - } - NSInteger numberOfPlaceholders = 42 - dates.count; - NSInteger numberOfPlaceholdersForPrev = [dates[0] fs_weekday]-1 ? : 7; - for (int i = 0; i < numberOfPlaceholdersForPrev; i++) { - [dates insertObject:[dates[0] fs_dateBySubtractingDays:1] atIndex:0]; - } - for (int i = 0; i < numberOfPlaceholders-numberOfPlaceholdersForPrev; i++) { - [dates addObject:[dates.lastObject fs_dateByAddingDays:1]]; - } - [self.subviews enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { - NSDate *date = dates[idx]; - [obj setDate: date]; - [obj setTag: date.fs_year*10000 + date.fs_month*100 + date.fs_day*100]; - }]; -} - -- (FSCalendarUnit *)unitForDate:(NSDate *)date -{ - NSInteger tag = date.fs_year*10000 + date.fs_month*100 + date.fs_day*100; - return (FSCalendarUnit *)[self viewWithTag:tag]; -} - -- (FSCalendar *)calendarView -{ - return (FSCalendar *)self.superview.superview; -} - - -@end diff --git a/Pod/Classes/FSCalendarUnit.h b/Pod/Classes/FSCalendarUnit.h deleted file mode 100644 index 05edb70..0000000 --- a/Pod/Classes/FSCalendarUnit.h +++ /dev/null @@ -1,60 +0,0 @@ -// -// FSCalendarViewUnit.h -// Pods -// -// Created by Wenchao Ding on 29/1/15. -// -// - -#import -#import "FSCalendar.h" - -@class FSCalendar; - -@protocol FSCalendarUnitDataSource, FSCalendarUnitDelegate; - -@interface FSCalendarUnit : UIView - -@property (weak, nonatomic) id dataSource; -@property (weak, nonatomic) id delegate; - -@property (assign, nonatomic) FSCalendarUnitAnimation animation; -@property (assign, nonatomic) FSCalendarUnitStyle style; - -@property (nonatomic) UIFont *subtitleFont; -@property (nonatomic) UIFont *titleFont; -@property (strong, nonatomic) UIColor *eventColor; - -@property (nonatomic, readonly, getter = isSelected) BOOL selected; -@property (nonatomic, readonly, getter = isPlaceholder) BOOL placeholder; -@property (nonatomic, readonly, getter = isToday) BOOL today; -@property (nonatomic, readonly, getter = isWeekend) BOOL weekend; - -@property (nonatomic, readonly) FSCalendarUnitState absoluteState; - -@property (strong, nonatomic) NSDate *date; - -@end - -@protocol FSCalendarUnitDataSource - -- (BOOL)unitIsPlaceholder:(FSCalendarUnit *)unit; -- (BOOL)unitIsToday:(FSCalendarUnit *)unit; -- (BOOL)unitIsSelected:(FSCalendarUnit *)unit; - -- (NSString *)subtitleForUnit:(FSCalendarUnit *)unit; -- (BOOL)hasEventForUnit:(FSCalendarUnit *)unit; - -- (UIColor *)unitColorForUnit:(FSCalendarUnit *)unit; -- (UIColor *)titleColorForUnit:(FSCalendarUnit *)unit; -- (UIColor *)subtitleColorForUnit:(FSCalendarUnit *)unit; - -@end - -@protocol FSCalendarUnitDelegate - -- (void)handleUnitTap:(FSCalendarUnit *)unit; - -@end - - diff --git a/Pod/Classes/FSCalendarUnit.m b/Pod/Classes/FSCalendarUnit.m deleted file mode 100644 index eb64c6c..0000000 --- a/Pod/Classes/FSCalendarUnit.m +++ /dev/null @@ -1,269 +0,0 @@ -// -// FSCalendarViewUnit.m -// Pods -// -// Created by Wenchao Ding on 29/1/15. -// -// - -#import "FSCalendarUnit.h" -#import "FSCalendarPage.h" -#import "NSDate+FSExtension.h" -#import "UIView+FSExtension.h" -#import - -#define kAnimationDuration 0.12 - -#define kTitleHeight self.fs_height*5.0/6.0 -#define kDiameter MIN(self.fs_height*5.0/6.0,self.fs_width) - -@interface FSCalendarUnit () - -@property (strong, nonatomic) UILabel *titleLabel; -@property (strong, nonatomic) UILabel *subtitleLabel; - -@property (strong, nonatomic) CAShapeLayer *animLayer; -@property (strong, nonatomic) CAShapeLayer *eventLayer; - -- (void)handleTap:(FSCalendarUnit *)unit; - -@end - -@implementation FSCalendarUnit - -@synthesize titleFont = _titleFont; - -- (instancetype)initWithFrame:(CGRect)frame -{ - self = [super initWithFrame:frame]; - if (self) { - - _titleLabel = [[UILabel alloc] initWithFrame:CGRectZero]; - _titleLabel.textAlignment = NSTextAlignmentCenter; - _titleLabel.font = [UIFont systemFontOfSize:15]; - [self addSubview:_titleLabel]; - - _subtitleLabel = [[UILabel alloc] initWithFrame:CGRectZero]; - _subtitleLabel.textAlignment = NSTextAlignmentCenter; - _subtitleLabel.font = [UIFont systemFontOfSize:10]; - [self addSubview:_subtitleLabel]; - - UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)]; - tapGesture.numberOfTapsRequired = 1; - tapGesture.numberOfTouchesRequired = 1; - tapGesture.cancelsTouchesInView = NO; - tapGesture.delaysTouchesBegan = NO; - [self addGestureRecognizer:tapGesture]; - - _animation = FSCalendarUnitAnimationScale; - - _eventLayer = [CAShapeLayer layer]; - _eventLayer.backgroundColor = [UIColor clearColor].CGColor; - _eventLayer.fillColor = [UIColor cyanColor].CGColor; - _eventLayer.path = [UIBezierPath bezierPathWithOvalInRect:_eventLayer.bounds].CGPath; - [self.layer addSublayer:_eventLayer]; - - _animLayer = [CAShapeLayer layer]; - [self.layer insertSublayer:_animLayer below:_titleLabel.layer]; - _style = FSCalendarUnitStyleCircle; - - self.clipsToBounds = NO; - } - return self; -} - -- (void)layoutSublayersOfLayer:(CALayer *)layer -{ - [super layoutSublayersOfLayer:layer]; - - if (layer == self.layer) { - - CGFloat diameter = kDiameter; - _animLayer.frame = CGRectMake((self.fs_width-diameter)/2, (kTitleHeight-diameter)/2, diameter, diameter); - - switch (self.style) { - case FSCalendarUnitStyleCircle: - _animLayer.path = [UIBezierPath bezierPathWithOvalInRect:_animLayer.bounds].CGPath; - break; - case FSCalendarUnitStyleRectangle: - _animLayer.path = [UIBezierPath bezierPathWithRect:_animLayer.bounds].CGPath; - break; - default: - break; - } - _animLayer.fillColor = [self.dataSource unitColorForUnit:self].CGColor; - - CGFloat eventSize = _animLayer.frame.size.height/6.0; - _eventLayer.frame = CGRectMake((_animLayer.frame.size.width-eventSize)/2+_animLayer.frame.origin.x, CGRectGetMaxY(_animLayer.frame)+eventSize*0.2, eventSize*0.8, eventSize*0.8); - _eventLayer.path = [UIBezierPath bezierPathWithOvalInRect:_eventLayer.bounds].CGPath; - _eventLayer.hidden = ![self.dataSource hasEventForUnit:self]; - - if ([self isSelected]) { - [self showAnimation]; - } - } -} - -- (void)layoutSubviews -{ - [super layoutSubviews]; - - if (_date) { - // set attribute title - NSString *subtitle = [_dataSource subtitleForUnit:self]; - UIColor *titleColor = [self.dataSource titleColorForUnit:self]; - NSString *title = [NSString stringWithFormat:@"%@", @(_date.fs_day)]; - _titleLabel.text = title; - _titleLabel.textColor = titleColor; - CGFloat titleHeight = [title sizeWithAttributes:@{NSFontAttributeName:self.titleFont}].height; - if (subtitle) { - _subtitleLabel.hidden = NO; - _subtitleLabel.text = subtitle; - CGFloat subtitleHeight = [subtitle sizeWithAttributes:@{NSFontAttributeName:self.subtitleFont}].height; - CGFloat height = titleHeight + subtitleHeight; - _titleLabel.frame = CGRectMake(0, - (kTitleHeight-height)*0.5, - self.fs_width, - titleHeight); - - _subtitleLabel.frame = CGRectMake(0, - height-subtitleHeight, - self.fs_width, - subtitleHeight); - _subtitleLabel.textColor = [self.dataSource subtitleColorForUnit:self]; - } else { - _titleLabel.frame = CGRectMake(0, 0, self.fs_width, floor(kTitleHeight)); - _subtitleLabel.hidden = YES; - } - } -} - -#pragma mark - Public - -- (void)setDate:(NSDate *)date -{ - if (![_date isEqualToDate:date]) { - _date = [date copy]; - } - [self setNeedsLayout]; -} - -- (void)setTitleFont:(UIFont *)titleFont -{ - if (_titleLabel.font != titleFont) { - _titleLabel.font = titleFont; - } -} - -- (UIFont *)titleFont -{ - return _titleLabel.font; -} - -- (void)setSubtitleFont:(UIFont *)subtitleFont -{ - if (_subtitleLabel.font != subtitleFont) { - _subtitleLabel.font = subtitleFont; - } -} - -- (UIFont *)subtitleFont -{ - return _subtitleLabel.font; -} - -- (void)setEventColor:(UIColor *)eventColor -{ - _eventLayer.fillColor = eventColor.CGColor; -} - -- (UIColor *)eventColor -{ - return [UIColor colorWithCGColor:_eventLayer.fillColor]; -} - -- (void)setStyle:(FSCalendarUnitStyle)style -{ - if (_style != style) { - _style = style; - [self setNeedsLayout]; - } -} - -#pragma mark - Target Action - -- (void)handleTap:(id)sender -{ - [self.delegate handleUnitTap:self]; -} - -#pragma mark - Private - -- (BOOL)isSelected -{ - return [self.dataSource unitIsSelected:self]; -} - -- (BOOL)isPlaceholder -{ - return [_dataSource unitIsPlaceholder:self]; -} - -- (BOOL)isToday -{ - return [_dataSource unitIsToday:self]; -} - -- (BOOL)isWeekend -{ - return self.date.fs_weekday == 1 || self.date.fs_weekday == 7; -} - -- (void)showAnimation -{ - if (_animation == FSCalendarUnitAnimationNone) { - return; - } - if (_animation == FSCalendarUnitAnimationScale) { - CAAnimationGroup *group = [CAAnimationGroup animation]; - CABasicAnimation *zoomOut = [CABasicAnimation animationWithKeyPath:@"transform.scale"]; - zoomOut.fromValue = @0.3; - zoomOut.toValue = @1.2; - zoomOut.duration = kAnimationDuration/4*3; - CABasicAnimation *zoomIn = [CABasicAnimation animationWithKeyPath:@"transform.scale"]; - zoomIn.fromValue = @1.2; - zoomIn.toValue = @1.0; - zoomIn.beginTime = kAnimationDuration/4*3; - zoomIn.duration = kAnimationDuration/4; - group.duration = kAnimationDuration; - group.animations = @[zoomOut, zoomIn]; - [_animLayer addAnimation:group forKey:@"bounce"]; - - } else if (_animation == FSCalendarUnitAnimationShade) { - [UIView transitionWithView:self duration:kAnimationDuration options:UIViewAnimationOptionTransitionCrossDissolve animations:^{ - [self setNeedsLayout]; - } completion:nil]; - } - -} - -- (FSCalendarUnitState)absoluteState -{ - if (self.isSelected) { - return FSCalendarUnitStateSelected; - } - if (self.isToday) { - return FSCalendarUnitStateToday; - } - if (self.isPlaceholder) { - return FSCalendarUnitStatePlaceholder; - } - if (self.isWeekend) { - return FSCalendarUnitStateWeekend; - } - return FSCalendarUnitStateNormal; -} - -@end - - diff --git a/Pod/Classes/UIScrollView+FSExtension.h b/Pod/Classes/UIScrollView+FSExtension.h deleted file mode 100644 index ad16e75..0000000 --- a/Pod/Classes/UIScrollView+FSExtension.h +++ /dev/null @@ -1,15 +0,0 @@ -// -// UIScrollView+FSExtension.h -// Pods -// -// Created by Wenchao Ding on 5/3/15. -// -// - -#import - -@interface UIScrollView (FSExtension) - -- (void)fs_scrollBy:(CGPoint)offset animate:(BOOL)animate; - -@end diff --git a/Pod/Classes/UIScrollView+FSExtension.m b/Pod/Classes/UIScrollView+FSExtension.m deleted file mode 100644 index 7a96644..0000000 --- a/Pod/Classes/UIScrollView+FSExtension.m +++ /dev/null @@ -1,22 +0,0 @@ -// -// UIScrollView+FSExtension.m -// Pods -// -// Created by Wenchao Ding on 5/3/15. -// -// - -#import "UIScrollView+FSExtension.h" - -@implementation UIScrollView (FSExtension) - -- (void)fs_scrollBy:(CGPoint)offset animate:(BOOL)animate -{ - if (!animate) { - self.contentOffset = CGPointMake(self.contentOffset.x+offset.x, self.contentOffset.y+offset.y); - } else { - - } -} - -@end