├── CJCalendar.podspec ├── CJCalendar.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ └── contents.xcworkspacedata └── xcuserdata │ └── chjsun.xcuserdatad │ ├── xcdebugger │ └── Breakpoints_v2.xcbkptlist │ └── xcschemes │ ├── CJCalendar.xcscheme │ └── xcschememanagement.plist ├── CJCalendar ├── AppDelegate.h ├── AppDelegate.m ├── Assets.xcassets │ ├── AppIcon.appiconset │ │ └── Contents.json │ └── Contents.json ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard ├── Info.plist ├── ViewController.h ├── ViewController.m ├── calendar │ ├── controller │ │ ├── CJCalendarViewController.h │ │ ├── CJCalendarViewController.m │ │ ├── CJMonthDayViewController.h │ │ ├── CJMonthDayViewController.m │ │ ├── CJYearViewController.h │ │ └── CJYearViewController.m │ ├── service │ │ ├── CJUseTime.h │ │ └── CJUseTime.m │ └── view │ │ ├── CJDecisionView.h │ │ ├── CJDecisionView.m │ │ ├── CJMonthDayCollectionCell.h │ │ ├── CJMonthDayCollectionCell.m │ │ ├── CJMonthDayCollectionCell.xib │ │ ├── CJSelectTimeScrollView.h │ │ ├── CJSelectTimeScrollView.m │ │ ├── CJShowTimeView.h │ │ └── CJShowTimeView.m └── main.m ├── CJCalendarTests ├── CJCalendarTests.m └── Info.plist ├── LICENSE.md └── README.md /CJCalendar.podspec: -------------------------------------------------------------------------------- 1 | # 2 | # Be sure to run `pod spec lint CJCalendar.podspec' to ensure this is a 3 | # valid spec and to remove all comments including this before submitting the spec. 4 | # 5 | # To learn more about Podspec attributes see http://docs.cocoapods.org/specification.html 6 | # To see working Podspecs in the CocoaPods repo see https://github.com/CocoaPods/Specs/ 7 | # 8 | 9 | Pod::Spec.new do |s| 10 | 11 | # ――― Spec Metadata ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # 12 | # 13 | # These will help people to find your library, and whilst it 14 | # can feel like a chore to fill in it's definitely to your advantage. The 15 | # summary should be tweet-length, and the description more in depth. 16 | # 17 | 18 | s.name = "CJCalendar" 19 | s.version = "0.0.1" 20 | s.summary = "Convenient calendar control" 21 | 22 | # This description is used to generate tags and improve search results. 23 | # * Think: What does it do? Why did you write it? What is the focus? 24 | # * Try to keep it short, snappy and to the point. 25 | # * Write the description between the DESC delimiters below. 26 | # * Finally, don't worry about the indent, CocoaPods strips it! 27 | s.description = <<-DESC 28 | Integration calendar can be so simple 29 | DESC 30 | 31 | s.homepage = "https://github.com/chjsun/CJCalendar" 32 | # s.screenshots = "www.example.com/screenshots_1.gif", "www.example.com/screenshots_2.gif" 33 | 34 | 35 | # ――― Spec License ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # 36 | # 37 | # Licensing your code is important. See http://choosealicense.com for more info. 38 | # CocoaPods will detect a license file if there is a named LICENSE* 39 | # Popular ones are 'MIT', 'BSD' and 'Apache License, Version 2.0'. 40 | # 41 | 42 | s.license = "MIT" 43 | # s.license = { :type => "MIT", :file => "FILE_LICENSE" } 44 | 45 | 46 | # ――― Author Metadata ――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # 47 | # 48 | # Specify the authors of the library, with email addresses. Email addresses 49 | # of the authors are extracted from the SCM log. E.g. $ git log. CocoaPods also 50 | # accepts just a name if you'd rather not provide an email address. 51 | # 52 | # Specify a social_media_url where others can refer to, for example a twitter 53 | # profile URL. 54 | # 55 | 56 | s.author = { "chjsun" => "scj126yx@126.com" } 57 | # Or just: s.author = "chjsun" 58 | # s.authors = { "chjsun" => "scj126yx@126.com" } 59 | # s.social_media_url = "http://twitter.com/chjsun" 60 | 61 | # ――― Platform Specifics ――――――――――――――――――――――――――――――――――――――――――――――――――――――― # 62 | # 63 | # If this Pod runs only on iOS or OS X, then specify the platform and 64 | # the deployment target. You can optionally include the target after the platform. 65 | # 66 | 67 | # s.platform = :ios 68 | s.platform = :ios, "8.0" 69 | 70 | # When using multiple platforms 71 | # s.ios.deployment_target = "5.0" 72 | # s.osx.deployment_target = "10.7" 73 | # s.watchos.deployment_target = "2.0" 74 | # s.tvos.deployment_target = "9.0" 75 | 76 | 77 | # ――― Source Location ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # 78 | # 79 | # Specify the location from where the source should be retrieved. 80 | # Supports git, hg, bzr, svn and HTTP. 81 | # 82 | 83 | s.source = { :git => "https://github.com/chjsun/CJCalendar.git", :tag => "0.0.1" } 84 | 85 | 86 | # ――― Source Code ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # 87 | # CocoaPods is smart about how it includes source code. For source files 88 | # giving a folder will include any swift, h, m, mm, c & cpp files. 89 | # For header files it will include any header in the folder. 90 | # Not including the public_header_files will make all headers public. 91 | # 92 | 93 | s.source_files = "CJCalendar/calendar/**/*.{h,m,xib}" 94 | #s.exclude_files = "CJCalendar/calendar" 95 | #s.framework = "UIKit" 96 | 97 | # s.public_header_files = "Classes/**/*.h" 98 | 99 | 100 | # ――― Resources ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # 101 | # 102 | # A list of resources included with the Pod. These are copied into the 103 | # target bundle with a build phase script. Anything else will be cleaned. 104 | # You can preserve files from being cleaned, please don't preserve 105 | # non-essential files like tests, examples and documentation. 106 | # 107 | 108 | # s.resource = "icon.png" 109 | # s.resources = "Resources/*.png" 110 | 111 | # s.preserve_paths = "FilesToSave", "MoreFilesToSave" 112 | 113 | 114 | # ――― Project Linking ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # 115 | # 116 | # Link your library with frameworks, or libraries. Libraries do not include 117 | # the lib prefix of their name. 118 | # 119 | 120 | # s.framework = "SomeFramework" 121 | # s.frameworks = "SomeFramework", "AnotherFramework" 122 | 123 | # s.library = "iconv" 124 | # s.libraries = "iconv", "xml2" 125 | 126 | 127 | # ――― Project Settings ――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # 128 | # 129 | # If your library depends on compiler flags you can set them in the xcconfig hash 130 | # where they will only apply to your library. If you depend on other Podspecs 131 | # you can include multiple dependencies to ensure it works. 132 | 133 | # s.requires_arc = true 134 | 135 | # s.xcconfig = { "HEADER_SEARCH_PATHS" => "$(SDKROOT)/usr/include/libxml2" } 136 | # s.dependency "JSONKit", "~> 1.4" 137 | 138 | end 139 | -------------------------------------------------------------------------------- /CJCalendar.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 940A5C2F1CF5FE5C00D72C35 /* CJDecisionView.m in Sources */ = {isa = PBXBuildFile; fileRef = 940A5C2E1CF5FE5C00D72C35 /* CJDecisionView.m */; }; 11 | 940A5C331CF6958300D72C35 /* CJUseTime.m in Sources */ = {isa = PBXBuildFile; fileRef = 940A5C321CF6958300D72C35 /* CJUseTime.m */; }; 12 | 940A5C371CF6EC7E00D72C35 /* CJMonthDayCollectionCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 940A5C351CF6EC7E00D72C35 /* CJMonthDayCollectionCell.m */; }; 13 | 940A5C381CF6EC7E00D72C35 /* CJMonthDayCollectionCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 940A5C361CF6EC7E00D72C35 /* CJMonthDayCollectionCell.xib */; }; 14 | 940A5C721CFAC3CD00D72C35 /* CJSelectTimeScrollView.m in Sources */ = {isa = PBXBuildFile; fileRef = 940A5C711CFAC3CD00D72C35 /* CJSelectTimeScrollView.m */; }; 15 | 940BFB201CF29FB3000BF56F /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 940BFB1F1CF29FB3000BF56F /* main.m */; }; 16 | 940BFB231CF29FB3000BF56F /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 940BFB221CF29FB3000BF56F /* AppDelegate.m */; }; 17 | 940BFB261CF29FB3000BF56F /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 940BFB251CF29FB3000BF56F /* ViewController.m */; }; 18 | 940BFB291CF29FB3000BF56F /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 940BFB271CF29FB3000BF56F /* Main.storyboard */; }; 19 | 940BFB2B1CF29FB3000BF56F /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 940BFB2A1CF29FB3000BF56F /* Assets.xcassets */; }; 20 | 940BFB2E1CF29FB3000BF56F /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 940BFB2C1CF29FB3000BF56F /* LaunchScreen.storyboard */; }; 21 | 940BFB391CF29FB4000BF56F /* CJCalendarTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 940BFB381CF29FB4000BF56F /* CJCalendarTests.m */; }; 22 | 940BFB4C1CF2FF60000BF56F /* CJShowTimeView.m in Sources */ = {isa = PBXBuildFile; fileRef = 940BFB4B1CF2FF60000BF56F /* CJShowTimeView.m */; }; 23 | 94457EB91CF45ED9004E49BF /* CJCalendarViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 94457EB81CF45ED9004E49BF /* CJCalendarViewController.m */; }; 24 | 94457EBF1CF4A075004E49BF /* CJYearViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 94457EBE1CF4A075004E49BF /* CJYearViewController.m */; }; 25 | 94457EC21CF4A0A3004E49BF /* CJMonthDayViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 94457EC11CF4A0A3004E49BF /* CJMonthDayViewController.m */; }; 26 | /* End PBXBuildFile section */ 27 | 28 | /* Begin PBXContainerItemProxy section */ 29 | 940BFB351CF29FB4000BF56F /* PBXContainerItemProxy */ = { 30 | isa = PBXContainerItemProxy; 31 | containerPortal = 940BFB131CF29FB3000BF56F /* Project object */; 32 | proxyType = 1; 33 | remoteGlobalIDString = 940BFB1A1CF29FB3000BF56F; 34 | remoteInfo = CJCalendar; 35 | }; 36 | /* End PBXContainerItemProxy section */ 37 | 38 | /* Begin PBXFileReference section */ 39 | 940A5C2D1CF5FE5C00D72C35 /* CJDecisionView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CJDecisionView.h; sourceTree = ""; }; 40 | 940A5C2E1CF5FE5C00D72C35 /* CJDecisionView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CJDecisionView.m; sourceTree = ""; }; 41 | 940A5C311CF6958300D72C35 /* CJUseTime.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CJUseTime.h; sourceTree = ""; }; 42 | 940A5C321CF6958300D72C35 /* CJUseTime.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CJUseTime.m; sourceTree = ""; }; 43 | 940A5C341CF6EC7E00D72C35 /* CJMonthDayCollectionCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CJMonthDayCollectionCell.h; sourceTree = ""; }; 44 | 940A5C351CF6EC7E00D72C35 /* CJMonthDayCollectionCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CJMonthDayCollectionCell.m; sourceTree = ""; }; 45 | 940A5C361CF6EC7E00D72C35 /* CJMonthDayCollectionCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = CJMonthDayCollectionCell.xib; sourceTree = ""; }; 46 | 940A5C701CFAC3CD00D72C35 /* CJSelectTimeScrollView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CJSelectTimeScrollView.h; sourceTree = ""; }; 47 | 940A5C711CFAC3CD00D72C35 /* CJSelectTimeScrollView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CJSelectTimeScrollView.m; sourceTree = ""; }; 48 | 940BFB1B1CF29FB3000BF56F /* CJCalendar.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = CJCalendar.app; sourceTree = BUILT_PRODUCTS_DIR; }; 49 | 940BFB1F1CF29FB3000BF56F /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 50 | 940BFB211CF29FB3000BF56F /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 51 | 940BFB221CF29FB3000BF56F /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; 52 | 940BFB241CF29FB3000BF56F /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; }; 53 | 940BFB251CF29FB3000BF56F /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; 54 | 940BFB281CF29FB3000BF56F /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 55 | 940BFB2A1CF29FB3000BF56F /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 56 | 940BFB2D1CF29FB3000BF56F /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 57 | 940BFB2F1CF29FB3000BF56F /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 58 | 940BFB341CF29FB4000BF56F /* CJCalendarTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = CJCalendarTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 59 | 940BFB381CF29FB4000BF56F /* CJCalendarTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = CJCalendarTests.m; sourceTree = ""; }; 60 | 940BFB3A1CF29FB4000BF56F /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 61 | 940BFB4A1CF2FF60000BF56F /* CJShowTimeView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CJShowTimeView.h; sourceTree = ""; }; 62 | 940BFB4B1CF2FF60000BF56F /* CJShowTimeView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CJShowTimeView.m; sourceTree = ""; }; 63 | 94457EB71CF45ECE004E49BF /* CJCalendarViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CJCalendarViewController.h; sourceTree = ""; }; 64 | 94457EB81CF45ED9004E49BF /* CJCalendarViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CJCalendarViewController.m; sourceTree = ""; }; 65 | 94457EBD1CF4A075004E49BF /* CJYearViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CJYearViewController.h; sourceTree = ""; }; 66 | 94457EBE1CF4A075004E49BF /* CJYearViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CJYearViewController.m; sourceTree = ""; }; 67 | 94457EC01CF4A0A3004E49BF /* CJMonthDayViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CJMonthDayViewController.h; sourceTree = ""; }; 68 | 94457EC11CF4A0A3004E49BF /* CJMonthDayViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CJMonthDayViewController.m; sourceTree = ""; }; 69 | /* End PBXFileReference section */ 70 | 71 | /* Begin PBXFrameworksBuildPhase section */ 72 | 940BFB181CF29FB3000BF56F /* Frameworks */ = { 73 | isa = PBXFrameworksBuildPhase; 74 | buildActionMask = 2147483647; 75 | files = ( 76 | ); 77 | runOnlyForDeploymentPostprocessing = 0; 78 | }; 79 | 940BFB311CF29FB4000BF56F /* Frameworks */ = { 80 | isa = PBXFrameworksBuildPhase; 81 | buildActionMask = 2147483647; 82 | files = ( 83 | ); 84 | runOnlyForDeploymentPostprocessing = 0; 85 | }; 86 | /* End PBXFrameworksBuildPhase section */ 87 | 88 | /* Begin PBXGroup section */ 89 | 940A5C301CF6946600D72C35 /* service */ = { 90 | isa = PBXGroup; 91 | children = ( 92 | 940A5C311CF6958300D72C35 /* CJUseTime.h */, 93 | 940A5C321CF6958300D72C35 /* CJUseTime.m */, 94 | ); 95 | path = service; 96 | sourceTree = ""; 97 | }; 98 | 940BFB121CF29FB3000BF56F = { 99 | isa = PBXGroup; 100 | children = ( 101 | 940BFB1D1CF29FB3000BF56F /* CJCalendar */, 102 | 940BFB371CF29FB4000BF56F /* CJCalendarTests */, 103 | 940BFB1C1CF29FB3000BF56F /* Products */, 104 | ); 105 | sourceTree = ""; 106 | }; 107 | 940BFB1C1CF29FB3000BF56F /* Products */ = { 108 | isa = PBXGroup; 109 | children = ( 110 | 940BFB1B1CF29FB3000BF56F /* CJCalendar.app */, 111 | 940BFB341CF29FB4000BF56F /* CJCalendarTests.xctest */, 112 | ); 113 | name = Products; 114 | sourceTree = ""; 115 | }; 116 | 940BFB1D1CF29FB3000BF56F /* CJCalendar */ = { 117 | isa = PBXGroup; 118 | children = ( 119 | 940BFB431CF2EDF5000BF56F /* calendar */, 120 | 940BFB211CF29FB3000BF56F /* AppDelegate.h */, 121 | 940BFB221CF29FB3000BF56F /* AppDelegate.m */, 122 | 940BFB241CF29FB3000BF56F /* ViewController.h */, 123 | 940BFB251CF29FB3000BF56F /* ViewController.m */, 124 | 940BFB271CF29FB3000BF56F /* Main.storyboard */, 125 | 940BFB2A1CF29FB3000BF56F /* Assets.xcassets */, 126 | 940BFB2C1CF29FB3000BF56F /* LaunchScreen.storyboard */, 127 | 940BFB2F1CF29FB3000BF56F /* Info.plist */, 128 | 940BFB1E1CF29FB3000BF56F /* Supporting Files */, 129 | ); 130 | path = CJCalendar; 131 | sourceTree = ""; 132 | }; 133 | 940BFB1E1CF29FB3000BF56F /* Supporting Files */ = { 134 | isa = PBXGroup; 135 | children = ( 136 | 940BFB1F1CF29FB3000BF56F /* main.m */, 137 | ); 138 | name = "Supporting Files"; 139 | sourceTree = ""; 140 | }; 141 | 940BFB371CF29FB4000BF56F /* CJCalendarTests */ = { 142 | isa = PBXGroup; 143 | children = ( 144 | 940BFB381CF29FB4000BF56F /* CJCalendarTests.m */, 145 | 940BFB3A1CF29FB4000BF56F /* Info.plist */, 146 | ); 147 | path = CJCalendarTests; 148 | sourceTree = ""; 149 | }; 150 | 940BFB431CF2EDF5000BF56F /* calendar */ = { 151 | isa = PBXGroup; 152 | children = ( 153 | 940BFB441CF2EDF5000BF56F /* controller */, 154 | 940BFB451CF2EDF5000BF56F /* model */, 155 | 940BFB461CF2EDF5000BF56F /* view */, 156 | 940A5C301CF6946600D72C35 /* service */, 157 | ); 158 | path = calendar; 159 | sourceTree = ""; 160 | }; 161 | 940BFB441CF2EDF5000BF56F /* controller */ = { 162 | isa = PBXGroup; 163 | children = ( 164 | 94457EB71CF45ECE004E49BF /* CJCalendarViewController.h */, 165 | 94457EB81CF45ED9004E49BF /* CJCalendarViewController.m */, 166 | 94457EB61CF45E00004E49BF /* subController */, 167 | ); 168 | path = controller; 169 | sourceTree = ""; 170 | }; 171 | 940BFB451CF2EDF5000BF56F /* model */ = { 172 | isa = PBXGroup; 173 | children = ( 174 | ); 175 | path = model; 176 | sourceTree = ""; 177 | }; 178 | 940BFB461CF2EDF5000BF56F /* view */ = { 179 | isa = PBXGroup; 180 | children = ( 181 | 940BFB4A1CF2FF60000BF56F /* CJShowTimeView.h */, 182 | 940BFB4B1CF2FF60000BF56F /* CJShowTimeView.m */, 183 | 940A5C701CFAC3CD00D72C35 /* CJSelectTimeScrollView.h */, 184 | 940A5C711CFAC3CD00D72C35 /* CJSelectTimeScrollView.m */, 185 | 940A5C2D1CF5FE5C00D72C35 /* CJDecisionView.h */, 186 | 940A5C2E1CF5FE5C00D72C35 /* CJDecisionView.m */, 187 | 940A5C341CF6EC7E00D72C35 /* CJMonthDayCollectionCell.h */, 188 | 940A5C351CF6EC7E00D72C35 /* CJMonthDayCollectionCell.m */, 189 | 940A5C361CF6EC7E00D72C35 /* CJMonthDayCollectionCell.xib */, 190 | ); 191 | path = view; 192 | sourceTree = ""; 193 | }; 194 | 94457EB61CF45E00004E49BF /* subController */ = { 195 | isa = PBXGroup; 196 | children = ( 197 | 94457EBD1CF4A075004E49BF /* CJYearViewController.h */, 198 | 94457EBE1CF4A075004E49BF /* CJYearViewController.m */, 199 | 94457EC01CF4A0A3004E49BF /* CJMonthDayViewController.h */, 200 | 94457EC11CF4A0A3004E49BF /* CJMonthDayViewController.m */, 201 | ); 202 | name = subController; 203 | sourceTree = ""; 204 | }; 205 | /* End PBXGroup section */ 206 | 207 | /* Begin PBXNativeTarget section */ 208 | 940BFB1A1CF29FB3000BF56F /* CJCalendar */ = { 209 | isa = PBXNativeTarget; 210 | buildConfigurationList = 940BFB3D1CF29FB4000BF56F /* Build configuration list for PBXNativeTarget "CJCalendar" */; 211 | buildPhases = ( 212 | 940BFB171CF29FB3000BF56F /* Sources */, 213 | 940BFB181CF29FB3000BF56F /* Frameworks */, 214 | 940BFB191CF29FB3000BF56F /* Resources */, 215 | ); 216 | buildRules = ( 217 | ); 218 | dependencies = ( 219 | ); 220 | name = CJCalendar; 221 | productName = CJCalendar; 222 | productReference = 940BFB1B1CF29FB3000BF56F /* CJCalendar.app */; 223 | productType = "com.apple.product-type.application"; 224 | }; 225 | 940BFB331CF29FB4000BF56F /* CJCalendarTests */ = { 226 | isa = PBXNativeTarget; 227 | buildConfigurationList = 940BFB401CF29FB4000BF56F /* Build configuration list for PBXNativeTarget "CJCalendarTests" */; 228 | buildPhases = ( 229 | 940BFB301CF29FB4000BF56F /* Sources */, 230 | 940BFB311CF29FB4000BF56F /* Frameworks */, 231 | 940BFB321CF29FB4000BF56F /* Resources */, 232 | ); 233 | buildRules = ( 234 | ); 235 | dependencies = ( 236 | 940BFB361CF29FB4000BF56F /* PBXTargetDependency */, 237 | ); 238 | name = CJCalendarTests; 239 | productName = CJCalendarTests; 240 | productReference = 940BFB341CF29FB4000BF56F /* CJCalendarTests.xctest */; 241 | productType = "com.apple.product-type.bundle.unit-test"; 242 | }; 243 | /* End PBXNativeTarget section */ 244 | 245 | /* Begin PBXProject section */ 246 | 940BFB131CF29FB3000BF56F /* Project object */ = { 247 | isa = PBXProject; 248 | attributes = { 249 | CLASSPREFIX = CJ; 250 | LastUpgradeCheck = 0720; 251 | ORGANIZATIONNAME = chjsun; 252 | TargetAttributes = { 253 | 940BFB1A1CF29FB3000BF56F = { 254 | CreatedOnToolsVersion = 7.2.1; 255 | }; 256 | 940BFB331CF29FB4000BF56F = { 257 | CreatedOnToolsVersion = 7.2.1; 258 | DevelopmentTeam = 9852S7GL84; 259 | TestTargetID = 940BFB1A1CF29FB3000BF56F; 260 | }; 261 | }; 262 | }; 263 | buildConfigurationList = 940BFB161CF29FB3000BF56F /* Build configuration list for PBXProject "CJCalendar" */; 264 | compatibilityVersion = "Xcode 3.2"; 265 | developmentRegion = English; 266 | hasScannedForEncodings = 0; 267 | knownRegions = ( 268 | en, 269 | Base, 270 | ); 271 | mainGroup = 940BFB121CF29FB3000BF56F; 272 | productRefGroup = 940BFB1C1CF29FB3000BF56F /* Products */; 273 | projectDirPath = ""; 274 | projectRoot = ""; 275 | targets = ( 276 | 940BFB1A1CF29FB3000BF56F /* CJCalendar */, 277 | 940BFB331CF29FB4000BF56F /* CJCalendarTests */, 278 | ); 279 | }; 280 | /* End PBXProject section */ 281 | 282 | /* Begin PBXResourcesBuildPhase section */ 283 | 940BFB191CF29FB3000BF56F /* Resources */ = { 284 | isa = PBXResourcesBuildPhase; 285 | buildActionMask = 2147483647; 286 | files = ( 287 | 940BFB2E1CF29FB3000BF56F /* LaunchScreen.storyboard in Resources */, 288 | 940BFB2B1CF29FB3000BF56F /* Assets.xcassets in Resources */, 289 | 940A5C381CF6EC7E00D72C35 /* CJMonthDayCollectionCell.xib in Resources */, 290 | 940BFB291CF29FB3000BF56F /* Main.storyboard in Resources */, 291 | ); 292 | runOnlyForDeploymentPostprocessing = 0; 293 | }; 294 | 940BFB321CF29FB4000BF56F /* Resources */ = { 295 | isa = PBXResourcesBuildPhase; 296 | buildActionMask = 2147483647; 297 | files = ( 298 | ); 299 | runOnlyForDeploymentPostprocessing = 0; 300 | }; 301 | /* End PBXResourcesBuildPhase section */ 302 | 303 | /* Begin PBXSourcesBuildPhase section */ 304 | 940BFB171CF29FB3000BF56F /* Sources */ = { 305 | isa = PBXSourcesBuildPhase; 306 | buildActionMask = 2147483647; 307 | files = ( 308 | 940A5C721CFAC3CD00D72C35 /* CJSelectTimeScrollView.m in Sources */, 309 | 940A5C331CF6958300D72C35 /* CJUseTime.m in Sources */, 310 | 94457EB91CF45ED9004E49BF /* CJCalendarViewController.m in Sources */, 311 | 940A5C2F1CF5FE5C00D72C35 /* CJDecisionView.m in Sources */, 312 | 94457EC21CF4A0A3004E49BF /* CJMonthDayViewController.m in Sources */, 313 | 940A5C371CF6EC7E00D72C35 /* CJMonthDayCollectionCell.m in Sources */, 314 | 940BFB261CF29FB3000BF56F /* ViewController.m in Sources */, 315 | 94457EBF1CF4A075004E49BF /* CJYearViewController.m in Sources */, 316 | 940BFB4C1CF2FF60000BF56F /* CJShowTimeView.m in Sources */, 317 | 940BFB231CF29FB3000BF56F /* AppDelegate.m in Sources */, 318 | 940BFB201CF29FB3000BF56F /* main.m in Sources */, 319 | ); 320 | runOnlyForDeploymentPostprocessing = 0; 321 | }; 322 | 940BFB301CF29FB4000BF56F /* Sources */ = { 323 | isa = PBXSourcesBuildPhase; 324 | buildActionMask = 2147483647; 325 | files = ( 326 | 940BFB391CF29FB4000BF56F /* CJCalendarTests.m in Sources */, 327 | ); 328 | runOnlyForDeploymentPostprocessing = 0; 329 | }; 330 | /* End PBXSourcesBuildPhase section */ 331 | 332 | /* Begin PBXTargetDependency section */ 333 | 940BFB361CF29FB4000BF56F /* PBXTargetDependency */ = { 334 | isa = PBXTargetDependency; 335 | target = 940BFB1A1CF29FB3000BF56F /* CJCalendar */; 336 | targetProxy = 940BFB351CF29FB4000BF56F /* PBXContainerItemProxy */; 337 | }; 338 | /* End PBXTargetDependency section */ 339 | 340 | /* Begin PBXVariantGroup section */ 341 | 940BFB271CF29FB3000BF56F /* Main.storyboard */ = { 342 | isa = PBXVariantGroup; 343 | children = ( 344 | 940BFB281CF29FB3000BF56F /* Base */, 345 | ); 346 | name = Main.storyboard; 347 | sourceTree = ""; 348 | }; 349 | 940BFB2C1CF29FB3000BF56F /* LaunchScreen.storyboard */ = { 350 | isa = PBXVariantGroup; 351 | children = ( 352 | 940BFB2D1CF29FB3000BF56F /* Base */, 353 | ); 354 | name = LaunchScreen.storyboard; 355 | sourceTree = ""; 356 | }; 357 | /* End PBXVariantGroup section */ 358 | 359 | /* Begin XCBuildConfiguration section */ 360 | 940BFB3B1CF29FB4000BF56F /* Debug */ = { 361 | isa = XCBuildConfiguration; 362 | buildSettings = { 363 | ALWAYS_SEARCH_USER_PATHS = NO; 364 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 365 | CLANG_CXX_LIBRARY = "libc++"; 366 | CLANG_ENABLE_MODULES = YES; 367 | CLANG_ENABLE_OBJC_ARC = YES; 368 | CLANG_WARN_BOOL_CONVERSION = YES; 369 | CLANG_WARN_CONSTANT_CONVERSION = YES; 370 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 371 | CLANG_WARN_EMPTY_BODY = YES; 372 | CLANG_WARN_ENUM_CONVERSION = YES; 373 | CLANG_WARN_INT_CONVERSION = YES; 374 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 375 | CLANG_WARN_UNREACHABLE_CODE = YES; 376 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 377 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 378 | COPY_PHASE_STRIP = NO; 379 | DEBUG_INFORMATION_FORMAT = dwarf; 380 | ENABLE_STRICT_OBJC_MSGSEND = YES; 381 | ENABLE_TESTABILITY = YES; 382 | GCC_C_LANGUAGE_STANDARD = gnu99; 383 | GCC_DYNAMIC_NO_PIC = NO; 384 | GCC_NO_COMMON_BLOCKS = YES; 385 | GCC_OPTIMIZATION_LEVEL = 0; 386 | GCC_PREPROCESSOR_DEFINITIONS = ( 387 | "DEBUG=1", 388 | "$(inherited)", 389 | ); 390 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 391 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 392 | GCC_WARN_UNDECLARED_SELECTOR = YES; 393 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 394 | GCC_WARN_UNUSED_FUNCTION = YES; 395 | GCC_WARN_UNUSED_VARIABLE = YES; 396 | IPHONEOS_DEPLOYMENT_TARGET = 9.2; 397 | MTL_ENABLE_DEBUG_INFO = YES; 398 | ONLY_ACTIVE_ARCH = YES; 399 | SDKROOT = iphoneos; 400 | }; 401 | name = Debug; 402 | }; 403 | 940BFB3C1CF29FB4000BF56F /* Release */ = { 404 | isa = XCBuildConfiguration; 405 | buildSettings = { 406 | ALWAYS_SEARCH_USER_PATHS = NO; 407 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 408 | CLANG_CXX_LIBRARY = "libc++"; 409 | CLANG_ENABLE_MODULES = YES; 410 | CLANG_ENABLE_OBJC_ARC = YES; 411 | CLANG_WARN_BOOL_CONVERSION = YES; 412 | CLANG_WARN_CONSTANT_CONVERSION = YES; 413 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 414 | CLANG_WARN_EMPTY_BODY = YES; 415 | CLANG_WARN_ENUM_CONVERSION = YES; 416 | CLANG_WARN_INT_CONVERSION = YES; 417 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 418 | CLANG_WARN_UNREACHABLE_CODE = YES; 419 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 420 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 421 | COPY_PHASE_STRIP = NO; 422 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 423 | ENABLE_NS_ASSERTIONS = NO; 424 | ENABLE_STRICT_OBJC_MSGSEND = YES; 425 | GCC_C_LANGUAGE_STANDARD = gnu99; 426 | GCC_NO_COMMON_BLOCKS = YES; 427 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 428 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 429 | GCC_WARN_UNDECLARED_SELECTOR = YES; 430 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 431 | GCC_WARN_UNUSED_FUNCTION = YES; 432 | GCC_WARN_UNUSED_VARIABLE = YES; 433 | IPHONEOS_DEPLOYMENT_TARGET = 9.2; 434 | MTL_ENABLE_DEBUG_INFO = NO; 435 | SDKROOT = iphoneos; 436 | VALIDATE_PRODUCT = YES; 437 | }; 438 | name = Release; 439 | }; 440 | 940BFB3E1CF29FB4000BF56F /* Debug */ = { 441 | isa = XCBuildConfiguration; 442 | buildSettings = { 443 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 444 | CODE_SIGN_IDENTITY = "iPhone Developer"; 445 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 446 | INFOPLIST_FILE = CJCalendar/Info.plist; 447 | IPHONEOS_DEPLOYMENT_TARGET = 8.1; 448 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 449 | PRODUCT_BUNDLE_IDENTIFIER = com.chjsun.CJCalendar; 450 | PRODUCT_NAME = "$(TARGET_NAME)"; 451 | PROVISIONING_PROFILE = ""; 452 | }; 453 | name = Debug; 454 | }; 455 | 940BFB3F1CF29FB4000BF56F /* Release */ = { 456 | isa = XCBuildConfiguration; 457 | buildSettings = { 458 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 459 | CODE_SIGN_IDENTITY = "iPhone Developer"; 460 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 461 | INFOPLIST_FILE = CJCalendar/Info.plist; 462 | IPHONEOS_DEPLOYMENT_TARGET = 8.1; 463 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 464 | PRODUCT_BUNDLE_IDENTIFIER = com.chjsun.CJCalendar; 465 | PRODUCT_NAME = "$(TARGET_NAME)"; 466 | PROVISIONING_PROFILE = ""; 467 | }; 468 | name = Release; 469 | }; 470 | 940BFB411CF29FB4000BF56F /* Debug */ = { 471 | isa = XCBuildConfiguration; 472 | buildSettings = { 473 | BUNDLE_LOADER = "$(TEST_HOST)"; 474 | INFOPLIST_FILE = CJCalendarTests/Info.plist; 475 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 476 | PRODUCT_BUNDLE_IDENTIFIER = com.chjsun.CJCalendarTests; 477 | PRODUCT_NAME = "$(TARGET_NAME)"; 478 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/CJCalendar.app/CJCalendar"; 479 | }; 480 | name = Debug; 481 | }; 482 | 940BFB421CF29FB4000BF56F /* Release */ = { 483 | isa = XCBuildConfiguration; 484 | buildSettings = { 485 | BUNDLE_LOADER = "$(TEST_HOST)"; 486 | INFOPLIST_FILE = CJCalendarTests/Info.plist; 487 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 488 | PRODUCT_BUNDLE_IDENTIFIER = com.chjsun.CJCalendarTests; 489 | PRODUCT_NAME = "$(TARGET_NAME)"; 490 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/CJCalendar.app/CJCalendar"; 491 | }; 492 | name = Release; 493 | }; 494 | /* End XCBuildConfiguration section */ 495 | 496 | /* Begin XCConfigurationList section */ 497 | 940BFB161CF29FB3000BF56F /* Build configuration list for PBXProject "CJCalendar" */ = { 498 | isa = XCConfigurationList; 499 | buildConfigurations = ( 500 | 940BFB3B1CF29FB4000BF56F /* Debug */, 501 | 940BFB3C1CF29FB4000BF56F /* Release */, 502 | ); 503 | defaultConfigurationIsVisible = 0; 504 | defaultConfigurationName = Release; 505 | }; 506 | 940BFB3D1CF29FB4000BF56F /* Build configuration list for PBXNativeTarget "CJCalendar" */ = { 507 | isa = XCConfigurationList; 508 | buildConfigurations = ( 509 | 940BFB3E1CF29FB4000BF56F /* Debug */, 510 | 940BFB3F1CF29FB4000BF56F /* Release */, 511 | ); 512 | defaultConfigurationIsVisible = 0; 513 | defaultConfigurationName = Release; 514 | }; 515 | 940BFB401CF29FB4000BF56F /* Build configuration list for PBXNativeTarget "CJCalendarTests" */ = { 516 | isa = XCConfigurationList; 517 | buildConfigurations = ( 518 | 940BFB411CF29FB4000BF56F /* Debug */, 519 | 940BFB421CF29FB4000BF56F /* Release */, 520 | ); 521 | defaultConfigurationIsVisible = 0; 522 | defaultConfigurationName = Release; 523 | }; 524 | /* End XCConfigurationList section */ 525 | }; 526 | rootObject = 940BFB131CF29FB3000BF56F /* Project object */; 527 | } 528 | -------------------------------------------------------------------------------- /CJCalendar.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /CJCalendar.xcodeproj/xcuserdata/chjsun.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 8 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /CJCalendar.xcodeproj/xcuserdata/chjsun.xcuserdatad/xcschemes/CJCalendar.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 33 | 39 | 40 | 41 | 42 | 43 | 49 | 50 | 51 | 52 | 53 | 54 | 64 | 66 | 72 | 73 | 74 | 75 | 76 | 77 | 83 | 85 | 91 | 92 | 93 | 94 | 96 | 97 | 100 | 101 | 102 | -------------------------------------------------------------------------------- /CJCalendar.xcodeproj/xcuserdata/chjsun.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | CJCalendar.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | 940BFB1A1CF29FB3000BF56F 16 | 17 | primary 18 | 19 | 20 | 940BFB331CF29FB4000BF56F 21 | 22 | primary 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /CJCalendar/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // CJCalendar 4 | // 5 | // Created by chjsun on 16/5/23. 6 | // Copyright © 2016年 chjsun. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | 16 | @end 17 | 18 | -------------------------------------------------------------------------------- /CJCalendar/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // CJCalendar 4 | // 5 | // Created by chjsun on 16/5/23. 6 | // Copyright © 2016年 chjsun. All rights reserved. 7 | // 8 | 9 | #import "AppDelegate.h" 10 | 11 | @interface AppDelegate () 12 | 13 | @end 14 | 15 | @implementation AppDelegate 16 | 17 | 18 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 19 | // Override point for customization after application launch. 20 | return YES; 21 | } 22 | 23 | - (void)applicationWillResignActive:(UIApplication *)application { 24 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 25 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 26 | } 27 | 28 | - (void)applicationDidEnterBackground:(UIApplication *)application { 29 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 30 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 31 | } 32 | 33 | - (void)applicationWillEnterForeground:(UIApplication *)application { 34 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 35 | } 36 | 37 | - (void)applicationDidBecomeActive:(UIApplication *)application { 38 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 39 | } 40 | 41 | - (void)applicationWillTerminate:(UIApplication *)application { 42 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 43 | } 44 | 45 | @end 46 | -------------------------------------------------------------------------------- /CJCalendar/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | } 33 | ], 34 | "info" : { 35 | "version" : 1, 36 | "author" : "xcode" 37 | } 38 | } -------------------------------------------------------------------------------- /CJCalendar/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /CJCalendar/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /CJCalendar/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | Lorem ipsum dolor sit er elit lamet, consectetaur cillium adipisicing pecu, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Nam liber te conscient to factor tum poen legum odioque civiuda. 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | Lorem ipsum dolor sit er elit lamet, consectetaur cillium adipisicing pecu, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Nam liber te conscient to factor tum poen legum odioque civiuda. 40 | 41 | 42 | 43 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | -------------------------------------------------------------------------------- /CJCalendar/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIMainStoryboardFile 28 | Main 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UISupportedInterfaceOrientations 34 | 35 | UIInterfaceOrientationPortrait 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /CJCalendar/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // CJCalendar 4 | // 5 | // Created by chjsun on 16/5/23. 6 | // Copyright © 2016年 chjsun. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /CJCalendar/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // CJCalendar 4 | // 5 | // Created by chjsun on 16/5/23. 6 | // Copyright © 2016年 chjsun. All rights reserved. 7 | // 8 | 9 | #import "ViewController.h" 10 | 11 | #import "CJCalendarViewController.h" 12 | 13 | @interface ViewController () 14 | 15 | /** 按钮 */ 16 | @property (nonatomic, weak) UIButton *CJButton; 17 | 18 | @end 19 | 20 | @implementation ViewController 21 | 22 | 23 | - (void)viewDidLoad { 24 | [super viewDidLoad]; 25 | } 26 | 27 | 28 | - (IBAction)btnClick:(UIButton *)sender { 29 | self.CJButton = sender; 30 | CJCalendarViewController *calendarController = [[CJCalendarViewController alloc] init]; 31 | calendarController.view.frame = self.view.frame; 32 | 33 | calendarController.delegate = self; 34 | NSArray *arr = [sender.titleLabel.text componentsSeparatedByString:@"-"]; 35 | 36 | if (arr.count > 1) { 37 | [calendarController setYear:arr[0] month:arr[1] day:arr[2]]; 38 | } 39 | 40 | [self presentViewController:calendarController animated:YES completion:nil]; 41 | 42 | } 43 | 44 | -(void)CalendarViewController:(CJCalendarViewController *)controller didSelectActionYear:(NSString *)year month:(NSString *)month day:(NSString *)day{ 45 | 46 | [self.CJButton setTitle:[NSString stringWithFormat:@"%@-%@-%@", year, month, day] forState:UIControlStateNormal]; 47 | 48 | } 49 | 50 | @end 51 | -------------------------------------------------------------------------------- /CJCalendar/calendar/controller/CJCalendarViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // CJMainViewController.h 3 | // CJCalendar 4 | // 5 | // Created by chjsun on 16/5/23. 6 | // Copyright © 2016年 chjsun. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @class CJCalendarViewController; 12 | 13 | @protocol CalendarViewControllerDelegate 14 | 15 | @optional 16 | -(void) CalendarViewController:(CJCalendarViewController *)controller didSelectActionYear:(NSString *)year month:(NSString *)month day:(NSString *)day; 17 | 18 | @end 19 | 20 | @interface CJCalendarViewController : UIViewController 21 | 22 | // attr 23 | //以下属性均有默认值 24 | /** HeaderColor default white 上部显示区域标题的颜色*/ 25 | @property (nonatomic, copy) UIColor *headerColor; 26 | /** HeaderBackgroundColor default rgb (60, 45, 140) 上部显示区域标题栏背景颜色 */ 27 | @property (nonatomic, copy) UIColor *headerBackgroundColor; 28 | /** contentColor default white 上部显示区域内容文本颜色*/ 29 | @property (nonatomic, copy) UIColor *contentColor; 30 | /** contentBackgroundColor default rgb (71, 55, 169) 上部显示区域内容背景颜色*/ 31 | @property (nonatomic, copy) UIColor *contentBackgroundColor; 32 | 33 | 34 | /** 直接指定时间 */ 35 | @property (nonatomic, strong) NSDate *Date; 36 | 37 | /** 代理 */ 38 | @property (nonatomic, assign) id delegate; 39 | 40 | // method 41 | /** 传入年、月、日. 设置时间 */ 42 | -(void) setYear:(NSString *)year month:(NSString *)month day:(NSString *)day; 43 | /** 传入半透明程度 和颜色,设置背景。 默认黑色,透明度0.8 */ 44 | -(void) setBgAlpha:(CGFloat)alpha color:(UIColor *)bgColor; 45 | 46 | @end 47 | -------------------------------------------------------------------------------- /CJCalendar/calendar/controller/CJCalendarViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // CJMainViewController.m 3 | // CJCalendar 4 | // 5 | // Created by chjsun on 16/5/23. 6 | // Copyright © 2016年 chjsun. All rights reserved. 7 | // 8 | 9 | #import "CJCalendarViewController.h" 10 | 11 | #import "CJShowTimeView.h" 12 | #import "CJSelectTimeScrollView.h" 13 | #import "CJDecisionView.h" 14 | 15 | #import "CJUseTime.h" 16 | 17 | #define CJColor(r, g, b) ([UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:1]) 18 | 19 | #define CJEdgeWidth 40 20 | #define CJEdgeHeight 50 21 | 22 | /** 23 | 概览: 24 | 总共整个控件分为四个部分 1,a:头部,主要显示全部时间内容,通常显示阳历对应的中国农历时间 25 | 2,b:年月日板 主要显示年月日和控制选择年月日的视图 26 | 3,c:选择板,用来选择年或者月日 27 | 4,d:控制板,主要是将选择的数据返回给调用者,基本有三个按钮(今日), (取消), (确定) 28 | 计算: 29 | 注:h是需要显示的大小,一般是整个屏幕去掉自定义的edge,即h = width - 2 * CJEdgeHeight 30 | 1: 22 p 31 | 2: 3/8 * h - 33 + 22 p 32 | 3: h/2 33 | 4: h/8 - 11 34 | 计算思路: 1, 头部固定大小22 35 | 2, 选择板占整个可视界面的1/2 36 | 3, 三个控制板+一个头部=年月日板 37 | 38 | */ 39 | 40 | @interface CJCalendarViewController () 41 | 42 | /** 记录高度 */ 43 | @property (nonatomic, assign) CGFloat viewHeight; 44 | 45 | /** timeView */ 46 | @property (nonatomic, strong) CJShowTimeView *timeView; 47 | /** selectController */ 48 | @property (nonatomic, strong) CJSelectTimeScrollView *selectScrollView; 49 | /** 操作时间 */ 50 | @property (nonatomic, strong) CJUseTime *useTime; 51 | /** 背景 */ 52 | @property (nonatomic, weak) UIView *bgView; 53 | 54 | @end 55 | 56 | @implementation CJCalendarViewController 57 | 58 | -(instancetype)init{ 59 | 60 | if (self = [super init]) { 61 | self.view.frame = [UIScreen mainScreen].bounds; 62 | NSTimeZone *zone = [NSTimeZone systemTimeZone]; 63 | self.Date = [NSDate dateWithTimeIntervalSinceNow:zone.secondsFromGMT]; 64 | } 65 | 66 | return self; 67 | } 68 | 69 | -(CJShowTimeView *)timeView{ 70 | if (!_timeView) { 71 | CGFloat timeRectWidth = self.view.bounds.size.width - 2 * CJEdgeWidth; 72 | // (3/8 * h - 33 + 22) + (22) === (a+b) 73 | 74 | CGFloat timeRectHeight = (self.view.bounds.size.height - 2 * CJEdgeHeight) * 3 / 8 + 11; 75 | self.viewHeight += timeRectHeight; 76 | 77 | CGRect rect = CGRectMake(CJEdgeWidth, CJEdgeHeight, timeRectWidth, timeRectHeight); 78 | _timeView = [[CJShowTimeView alloc] initWithFrame:rect]; 79 | _timeView.delegate = self; 80 | } 81 | return _timeView; 82 | } 83 | 84 | -(CJSelectTimeScrollView *)selectScrollView{ 85 | if (!_selectScrollView) { 86 | _selectScrollView = [[CJSelectTimeScrollView alloc] init]; 87 | _selectScrollView.delegates = self; 88 | _selectScrollView.scrollEnabled = NO; 89 | } 90 | return _selectScrollView; 91 | } 92 | 93 | -(CJUseTime *)useTime{ 94 | if (!_useTime) { 95 | // _useTime = [[CJUseTime alloc] init]; 96 | _useTime = [CJUseTime sharedInstance]; 97 | } 98 | return _useTime; 99 | } 100 | 101 | - (void)viewDidLoad { 102 | [super viewDidLoad]; 103 | 104 | // 设置半透明背景 105 | [self setBackgroundView]; 106 | // 设置showTime 107 | [self setShowTimeView]; 108 | // 设置选择板 109 | [self setSelectTime]; 110 | // 设置控制板 111 | [self setDecision]; 112 | 113 | } 114 | 115 | // 即将显示的时候,做一下初始化操作 116 | -(void)viewDidAppear:(BOOL)animated{ 117 | [super viewDidAppear:animated]; 118 | 119 | // 初始化时将控制器跳转到指定时间 120 | self.selectScrollView.year = self.timeView.yearText; 121 | } 122 | 123 | // set background alpha 124 | // 设置背景 125 | -(void) setBackgroundView{ 126 | UIView *bgView = [[UIView alloc] initWithFrame:self.view.frame]; 127 | self.bgView = bgView; 128 | // 默认颜色及透明度 129 | bgView.backgroundColor = CJColor(29, 29, 29); 130 | bgView.alpha = 0.8; 131 | if([[[UIDevice currentDevice] systemVersion] floatValue]>=8.0) { 132 | self.modalPresentationStyle = UIModalPresentationOverCurrentContext; 133 | }else{ 134 | self.modalPresentationStyle = UIModalPresentationCurrentContext; 135 | } 136 | [self.view addSubview:bgView]; 137 | } 138 | 139 | // ser showTimeView 140 | // 设置在日历上方的头部显示面板 141 | -(void) setShowTimeView{ 142 | [self.timeView generateView]; 143 | 144 | [self.view addSubview:self.timeView]; 145 | } 146 | 147 | // set selectView 148 | // 设置日历选择面板 149 | -(void) setSelectTime{ 150 | 151 | CGFloat selectWidth = self.view.bounds.size.width - 2 * CJEdgeWidth; 152 | // (h - 2*edge)/2 153 | CGFloat selectHeight = (self.view.bounds.size.height - 2 * CJEdgeHeight)/2; 154 | CGRect selectRect = CGRectMake(CJEdgeWidth, CJEdgeHeight + self.viewHeight, selectWidth, selectHeight); 155 | self.viewHeight += selectHeight; 156 | 157 | self.selectScrollView.frame = selectRect; 158 | //设置scrollview的属性 159 | self.selectScrollView.contentSize = CGSizeMake(selectWidth * 2, selectHeight); 160 | self.selectScrollView.pagingEnabled = YES; 161 | self.selectScrollView.showsHorizontalScrollIndicator = FALSE; 162 | //设置所有的子控制器 163 | [self.selectScrollView setUpAllControllerWithSuperControll:self]; 164 | 165 | [self.view addSubview:self.selectScrollView]; 166 | 167 | } 168 | 169 | // set decisionView 170 | // 设置最后的按钮 171 | -(void) setDecision{ 172 | CGFloat selectWidth = self.view.bounds.size.width - 2 * CJEdgeWidth; 173 | // h/8 - 11 174 | CGFloat selectHeight = (self.view.bounds.size.height - 2 * CJEdgeHeight) / 8 - 11; 175 | CGRect rect = CGRectMake(CJEdgeWidth, CJEdgeHeight + self.viewHeight, selectWidth, selectHeight); 176 | 177 | CJDecisionView *decisionView = [[CJDecisionView alloc] initWithFrame:rect]; 178 | decisionView.backgroundColor = [UIColor whiteColor]; 179 | [decisionView generateDecision]; 180 | decisionView.delegate = self; 181 | 182 | [self.view addSubview:decisionView]; 183 | } 184 | 185 | 186 | #pragma mark - showViewDelegate 具体日历上方的时间显示区代理 187 | // 头部 月 日 -- 代理 188 | -(void)ShowTimeView:(CJShowTimeView *)timeView didSelectYear:(NSString *)year Month:(NSString *)month day:(NSString *)day{ 189 | [self.selectScrollView refreshControlWithYear:year month:month day:day]; 190 | [self setBoundsToScrollView:0]; 191 | } 192 | // 头部 年 -- 代理 193 | -(void)ShowTimeView:(CJShowTimeView *)timeView didSelectYear:(NSString *)year{ 194 | self.selectScrollView.year = year; 195 | [self setBoundsToScrollView:1]; 196 | } 197 | 198 | -(void) setBoundsToScrollView:(CGFloat)tag{ 199 | 200 | CGFloat selectWidth = self.view.bounds.size.width - 2 * CJEdgeWidth; 201 | // (h - 2*edge)/2 202 | CGFloat selectHeight = (self.view.bounds.size.height - 2 * CJEdgeHeight)/2; 203 | self.selectScrollView.bounds = CGRectMake(selectWidth * tag, 0, selectWidth, selectHeight); 204 | 205 | } 206 | #pragma mark - 选择日历面板控制器的代理 207 | // 年份选择 208 | -(void)selectTimeView:(CJSelectTimeScrollView *)timeScroll didSelectYearAtIndexPath:(NSIndexPath *)indexPath cellText:(NSString *)cellText{ 209 | 210 | NSString *gregorainToChinese; 211 | 212 | // 判断是不是2月29号 初步将2/29 转换为2/28 213 | BOOL is2M29D = (([self.timeView.monthText isEqualToString:@"02"] || [self.timeView.monthText isEqualToString:@"2"]) && [self.timeView.dayText isEqualToString:@"29"]); 214 | 215 | if (is2M29D) { 216 | gregorainToChinese = [self.useTime timeChineseCalendarWithString:[NSString stringWithFormat:@"%@-%@-%li",cellText, self.timeView.monthText, [self.timeView.dayText integerValue] - 1]]; 217 | self.timeView.dayText = @"28"; 218 | 219 | }else{ 220 | gregorainToChinese = [self.useTime timeChineseCalendarWithString:[NSString stringWithFormat:@"%@-%@-%@",cellText, self.timeView.monthText, self.timeView.dayText]]; 221 | } 222 | 223 | self.timeView.headerName = gregorainToChinese; 224 | self.timeView.yearText = cellText; 225 | 226 | } 227 | 228 | // 月份选择 229 | -(void)selectTimeView:(CJSelectTimeScrollView *)timeScroll didSelectMonthAndDayAtIndexPath:(NSIndexPath *)indexPath GregoiainCalendar:(NSString *)gregoiainCalendar chineseCalendar:(NSString *)chineseCalendar{ 230 | 231 | NSArray *calendar = [gregoiainCalendar componentsSeparatedByString:@"-"]; 232 | 233 | self.timeView.headerName = chineseCalendar; 234 | self.timeView.monthText = calendar[1]; 235 | self.timeView.dayText = calendar[2]; 236 | self.timeView.yearText = calendar[0]; 237 | 238 | } 239 | 240 | 241 | #pragma mark - 控制板按钮 242 | // 确定 243 | -(void)DecisionDidSelectAction:(CJDecisionView *)decision{ 244 | if ([self.delegate respondsToSelector:@selector(CalendarViewController:didSelectActionYear:month:day:)]) { 245 | // 代理传值, 将年月日信息传递给调用者 246 | [self.delegate CalendarViewController:self didSelectActionYear:self.timeView.yearText month:self.timeView.monthText day:self.timeView.dayText]; 247 | 248 | // dismiss 该控制器 249 | [self dismissViewControllerAnimated:YES completion:nil]; 250 | } 251 | } 252 | // 取消 253 | -(void)DecisionDidSelectCancel:(CJDecisionView *)decision{ 254 | [self dismissViewControllerAnimated:YES completion:nil]; 255 | } 256 | // 今日 257 | -(void)DecisionDidSelectNow:(CJDecisionView *)decision{ 258 | self.Date = [NSDate dateWithTimeIntervalSinceNow:[NSTimeZone systemTimeZone].secondsFromGMT]; 259 | } 260 | 261 | #pragma mark - 本类对外的操作 262 | 263 | // 设置指定时间 264 | 265 | -(void)setDate:(NSDate *)Date{ 266 | _Date = Date; 267 | [self setCustomDate:Date]; 268 | } 269 | 270 | -(void)setCustomDate:(NSDate *)Date{ 271 | NSArray *calendar = [[self.useTime dataToString:Date] componentsSeparatedByString:@"-"]; 272 | 273 | self.timeView.headerName = [self.useTime timeChineseCalendarWithDate:Date]; 274 | self.timeView.monthText = calendar[1]; 275 | self.timeView.dayText = calendar[2]; 276 | self.timeView.yearText = calendar[0]; 277 | [self.selectScrollView refreshControlWithYear:calendar[0] month:calendar[1] day:calendar[2]]; 278 | 279 | 280 | } 281 | // 设置指定年月日 282 | -(void)setYear:(NSString *)year month:(NSString *)month day:(NSString *)day{ 283 | NSDate *date = [self.useTime strToDate:[NSString stringWithFormat:@"%@-%@-%@", year? year: @1970, month? month: @1970, day? day: @1970]]; 284 | 285 | self.Date = date; 286 | } 287 | 288 | #pragma mark - 设置扩展属性 颜色 289 | 290 | - (void)setHeaderColor:(UIColor *)headerColor{ 291 | _headerColor = headerColor; 292 | self.timeView.headerColor = headerColor; 293 | } 294 | 295 | -(void)setHeaderBackgroundColor:(UIColor *)headerBackgroundColor{ 296 | _headerBackgroundColor = headerBackgroundColor; 297 | self.timeView.headerBackgroundColor = headerBackgroundColor; 298 | } 299 | 300 | - (void)setContentColor:(UIColor *)contentColor{ 301 | _contentColor = contentColor; 302 | self.timeView.contentColor = contentColor; 303 | 304 | } 305 | 306 | - (void)setContentBackgroundColor:(UIColor *)contentBackgroundColor{ 307 | _contentBackgroundColor = contentBackgroundColor; 308 | self.timeView.contentBackgroundColor = contentBackgroundColor; 309 | self.selectScrollView.selectYearColor = contentBackgroundColor; 310 | self.selectScrollView.selectMonthDayColor = contentBackgroundColor; 311 | } 312 | 313 | -(void)setBgAlpha:(CGFloat)alpha color:(UIColor *)bgColor{ 314 | self.bgView.alpha = alpha; 315 | self.bgView.backgroundColor = bgColor; 316 | } 317 | 318 | @end 319 | -------------------------------------------------------------------------------- /CJCalendar/calendar/controller/CJMonthDayViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // CJMonthDayViewController.h 3 | // CJCalendar 4 | // 5 | // Created by chjsun on 16/5/24. 6 | // Copyright © 2016年 chjsun. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @class CJMonthDayViewController; 12 | @protocol MonthAndDayControllerDelegate 13 | 14 | @optional 15 | -(void) monthAndDayController:(CJMonthDayViewController *)controller didSelectIndexPath:(NSIndexPath *)indexPath GregoiainCalendar:(NSString *)gregoiainCalendar chineseCalendar:(NSString *)chineseCalendar; 16 | 17 | @end 18 | 19 | @interface CJMonthDayViewController : UICollectionViewController 20 | 21 | /** 选中状态的color */ 22 | @property (nonatomic, strong) UIColor *selectColor; 23 | 24 | -(instancetype)initWithFrame:(CGRect)frame; 25 | 26 | /** 代理 */ 27 | @property (nonatomic, assign) id delegate; 28 | 29 | //根据时间更新collection 30 | -(void)refreshControlWithYear:(NSString *)year month:(NSString *)month day:(NSString *)day; 31 | 32 | @end 33 | -------------------------------------------------------------------------------- /CJCalendar/calendar/controller/CJMonthDayViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // CJMonthDayViewController.m 3 | // CJCalendar 4 | // 5 | // Created by chjsun on 16/5/24. 6 | // Copyright © 2016年 chjsun. All rights reserved. 7 | // 8 | 9 | #import "CJMonthDayViewController.h" 10 | 11 | #import "CJMonthDayCollectionCell.h" 12 | 13 | #import "CJUseTime.h" 14 | 15 | @interface CJMonthDayViewController () 16 | 17 | /** 公历某个月的天数 */ 18 | @property (nonatomic, assign) NSInteger monthNumber; 19 | /** 某天是星期几 */ 20 | @property (nonatomic, assign) NSInteger dayOfWeek; 21 | 22 | /** 月日,星期几 */ 23 | @property (nonatomic, strong) NSMutableArray *monthNumberAndWeek; 24 | 25 | /** 处理时间的方法 */ 26 | @property (nonatomic, strong) CJUseTime *useTime; 27 | 28 | @end 29 | 30 | @implementation CJMonthDayViewController 31 | 32 | static NSString * const reuseIdentifier = @"monthDayViewCell"; 33 | static NSString * const reuseHeader = @"monthDayViewHeader"; 34 | 35 | // 懒加载 36 | -(CJUseTime *)useTime{ 37 | if (!_useTime) { 38 | // _useTime = [[CJUseTime alloc] init]; 39 | _useTime = [CJUseTime sharedInstance]; 40 | } 41 | return _useTime; 42 | } 43 | 44 | -(instancetype)initWithFrame:(CGRect)frame{ 45 | UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init]; 46 | 47 | CGFloat wh = frame.size.width/7; 48 | layout.itemSize = CGSizeMake(wh, wh); 49 | layout.minimumLineSpacing = 5; 50 | layout.minimumInteritemSpacing = -2; 51 | layout.sectionInset = UIEdgeInsetsMake(10, 0, 15, 0); 52 | 53 | 54 | self = [super initWithCollectionViewLayout:layout]; 55 | self.view.frame = frame; 56 | self.collectionView.showsVerticalScrollIndicator = NO; 57 | self.collectionView.backgroundColor = [UIColor whiteColor]; 58 | 59 | return self; 60 | 61 | } 62 | 63 | - (void)viewDidLoad { 64 | [super viewDidLoad]; 65 | 66 | //注册 67 | [self.collectionView registerClass:[CJMonthDayCollectionCell class] forCellWithReuseIdentifier:reuseIdentifier]; 68 | //注册头部 69 | [self.collectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:reuseHeader]; 70 | } 71 | 72 | 73 | 74 | #pragma mark 75 | 76 | - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView { 77 | 78 | return (2101-1970) * 12; 79 | } 80 | 81 | 82 | - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { 83 | //每个月的第一天 84 | NSString *strYear = [NSString stringWithFormat:@"%ld", (section / 12 + 1970)]; 85 | NSString *strMonth = [NSString stringWithFormat:@"%ld", (section % 12 + 1)]; 86 | NSString *dateStr = [NSString stringWithFormat:@"%@-%@-01", strYear, strMonth]; 87 | 88 | return [self.useTime timeFewWeekInMonth:dateStr] * 7; 89 | } 90 | 91 | - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { 92 | 93 | CJMonthDayCollectionCell *cell = (CJMonthDayCollectionCell *)[collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath]; 94 | 95 | 96 | //每个月的第一天 97 | NSString *dateStr = [self getDateStrForSection:indexPath.section day:1]; 98 | // 获得这个月的天数 99 | self.monthNumber = [self.useTime timeNumberOfDaysInString:dateStr]; 100 | 101 | // 获得这个月第一天是星期几 102 | self.dayOfWeek = [self.useTime timeMonthWeekDayOfFirstDay:dateStr]; 103 | 104 | NSInteger firstCorner = self.dayOfWeek; 105 | NSInteger lastConter = self.dayOfWeek + self.monthNumber - 1; 106 | if (indexPath.item lastConter) { 107 | cell.hidden = YES; 108 | }else{ 109 | cell.hidden = NO; 110 | NSInteger gregoiain = indexPath.item - firstCorner+1; 111 | //阳历 112 | cell.gregoiainDay = [NSString stringWithFormat:@"%ld", (long)gregoiain]; 113 | 114 | //农历 115 | NSString *dateStr = [self getDateStrForSection:indexPath.section day:gregoiain]; 116 | cell.lunarDay = [self.useTime timeChineseDaysWithDate:dateStr]; 117 | 118 | //日期属性 119 | cell.gregoiainCalendar = dateStr; 120 | cell.chineseCalendar = [self.useTime timeChineseCalendarWithString:dateStr]; 121 | 122 | //设置选中后 123 | if (cell.selectedBackgroundView == nil) { 124 | CGRect rect = self.view.frame; 125 | CGFloat wh = rect.size.width/7; 126 | 127 | UIView *selectBgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, wh, wh)]; 128 | 129 | selectBgView.backgroundColor = self.selectColor; 130 | selectBgView.layer.cornerRadius = wh/2; 131 | selectBgView.layer.masksToBounds = YES; 132 | 133 | UIView *selectView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, wh, wh)]; 134 | 135 | [selectView addSubview:selectBgView]; 136 | cell.selectedBackgroundView = selectView; 137 | } 138 | 139 | } 140 | return cell; 141 | } 142 | 143 | 144 | //header 145 | -(UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{ 146 | 147 | if ([kind isEqualToString:UICollectionElementKindSectionHeader]) { 148 | 149 | UICollectionReusableView *headerView = [collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:reuseHeader forIndexPath:indexPath]; 150 | 151 | UILabel *label = [headerView viewWithTag:11]; 152 | if (label == nil) { 153 | // 添加日期 154 | label = [[UILabel alloc] init]; 155 | label.tag = 11; 156 | [headerView addSubview:label]; 157 | 158 | NSArray *weeks = @[@"日", @"一", @"二", @"三", @"四", @"五", @"六"]; 159 | //添加星期 160 | for (int i = 0; i < 7; i++) { 161 | NSString *weekStr = weeks[i]; 162 | UILabel *week = [[UILabel alloc] initWithFrame:CGRectMake( headerView.frame.size.width/7 * i, headerView.frame.size.height/2, headerView.frame.size.width/7, 22)]; 163 | week.font = [UIFont systemFontOfSize:15]; 164 | week.text = weekStr; 165 | week.textAlignment = NSTextAlignmentCenter; 166 | [headerView addSubview:week]; 167 | } 168 | 169 | } 170 | //设置属性 171 | label.text = [NSString stringWithFormat:@"%ld年 %ld", (indexPath.section/12 + 1970), (indexPath.section%12 + 1)]; 172 | 173 | [label sizeToFit]; 174 | 175 | CGFloat x = (headerView.frame.size.width - label.frame.size.width)/2; 176 | CGFloat y = (headerView.frame.size.height/2 - label.frame.size.height)/2; 177 | CGFloat width = label.frame.size.width; 178 | CGFloat height = label.frame.size.height; 179 | label.frame = CGRectMake(x, y, width, height); 180 | 181 | return headerView; 182 | } 183 | return nil; 184 | 185 | } 186 | 187 | -(NSString *)getDateStrForSection:(NSInteger)section day:(NSInteger)day{ 188 | return [NSString stringWithFormat:@"%ld-%ld-%ld", (section/12 + 1970), (section%12 + 1), (long)day]; 189 | } 190 | 191 | 192 | //设置header的高度 193 | - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section 194 | { 195 | CGFloat ScreenWidth = [UIScreen mainScreen].bounds.size.width; 196 | return (CGSize){ScreenWidth, 44}; 197 | } 198 | 199 | //cell点击 200 | -(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{ 201 | CJMonthDayCollectionCell *cell = (CJMonthDayCollectionCell *)[collectionView cellForItemAtIndexPath:indexPath]; 202 | 203 | if ([self.delegate respondsToSelector:@selector(monthAndDayController:didSelectIndexPath: GregoiainCalendar:chineseCalendar:)]){ 204 | 205 | [self.delegate monthAndDayController:self didSelectIndexPath:indexPath GregoiainCalendar:cell.gregoiainCalendar chineseCalendar:cell.chineseCalendar]; 206 | } 207 | } 208 | 209 | 210 | -(void)refreshControlWithYear:(NSString *)year month:(NSString *)month day:(NSString *)day{ 211 | // 每个月的第一天 212 | // (2101-1970) * 12 213 | NSString *dateStr = [NSString stringWithFormat:@"%@-%@-%@", year, month, @1]; 214 | // 获得这个月第一天是星期几 215 | NSInteger dayOfFirstWeek = [self.useTime timeMonthWeekDayOfFirstDay:dateStr]; 216 | 217 | NSInteger section = ([year integerValue] - 1970)*12 + ([month integerValue] - 1); 218 | NSInteger item = [day integerValue] + dayOfFirstWeek - 1; 219 | 220 | NSIndexPath *indexPath = [NSIndexPath indexPathForItem:item inSection:section]; 221 | 222 | [self.collectionView selectItemAtIndexPath:indexPath animated:NO scrollPosition:UICollectionViewScrollPositionCenteredVertically]; 223 | } 224 | 225 | @end 226 | -------------------------------------------------------------------------------- /CJCalendar/calendar/controller/CJYearViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // CJYearViewController.h 3 | // CJCalendar 4 | // 5 | // Created by chjsun on 16/5/24. 6 | // Copyright © 2016年 chjsun. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @protocol YearViewControllerDelegate 12 | 13 | @optional 14 | -(void)yearTableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath cellText:(NSString *)cellText; 15 | 16 | @end 17 | 18 | @interface CJYearViewController : UITableViewController 19 | 20 | /** 选中状态的color */ 21 | @property (nonatomic, strong) UIColor *selectColor; 22 | 23 | // 根据时间更新tableview 24 | -(void) refreshControlWithCellText: (NSString *)year; 25 | 26 | /** 代理 */ 27 | @property (nonatomic, assign) id delegate; 28 | 29 | @end 30 | -------------------------------------------------------------------------------- /CJCalendar/calendar/controller/CJYearViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // CJYearViewController.m 3 | // CJCalendar 4 | // 5 | // Created by chjsun on 16/5/24. 6 | // Copyright © 2016年 chjsun. All rights reserved. 7 | // 8 | 9 | #import "CJYearViewController.h" 10 | 11 | @interface CJYearViewController () 12 | 13 | /** indexPaht */ 14 | @property (nonatomic, assign) NSIndexPath *selectIndexPath; 15 | 16 | @end 17 | 18 | static NSString * const reuseIdentifier = @"yearTableViewCell"; 19 | @implementation CJYearViewController 20 | 21 | - (void)viewDidLoad { 22 | [super viewDidLoad]; 23 | self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone; 24 | 25 | 26 | } 27 | 28 | #pragma mark - Table view data source 29 | 30 | - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 31 | return 1; 32 | } 33 | 34 | - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 35 | return 2101-1970; 36 | } 37 | 38 | 39 | - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 40 | 41 | // UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifier forIndexPath:indexPath]; 42 | UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifier]; 43 | 44 | 45 | if (cell == nil) { 46 | cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier]; 47 | cell.textLabel.highlightedTextColor = [UIColor whiteColor]; 48 | 49 | CGRect rect = self.view.frame; 50 | 51 | CGFloat height = rect.size.height/4; 52 | CGFloat width = height; 53 | CGFloat x = (rect.size.width - height)/2; 54 | CGFloat y = 0; 55 | 56 | UIView *selectView = [[UIView alloc] initWithFrame:CGRectMake(x, y, width, height)]; 57 | 58 | selectView.backgroundColor = self.selectColor; 59 | selectView.layer.cornerRadius = height/2; 60 | selectView.layer.masksToBounds = YES; 61 | 62 | UIView *selectBgView = [[UIView alloc] initWithFrame:cell.frame]; 63 | [selectBgView addSubview:selectView]; 64 | 65 | cell.selectedBackgroundView = selectBgView; 66 | } 67 | 68 | cell.textLabel.text = [NSString stringWithFormat:@"%ld", (long)indexPath.row + 1970]; 69 | cell.textLabel.font = [UIFont systemFontOfSize:22]; 70 | cell.textLabel.textAlignment = NSTextAlignmentCenter; 71 | 72 | return cell; 73 | } 74 | 75 | -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ 76 | return self.view.frame.size.height/4; 77 | } 78 | 79 | -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ 80 | 81 | UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; 82 | self.selectIndexPath = indexPath; 83 | [self.tableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionMiddle]; 84 | 85 | if ([self.delegate respondsToSelector:@selector(yearTableView:didSelectRowAtIndexPath:cellText:)]) { 86 | 87 | [self.delegate yearTableView:tableView didSelectRowAtIndexPath:indexPath cellText:cell.textLabel.text]; 88 | } 89 | } 90 | 91 | 92 | -(void)refreshControlWithCellText:(NSString *)year{ 93 | NSUInteger row = [year integerValue] - 1970; 94 | NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:CGPointMake(10, row * self.view.frame.size.height/4+1)]; 95 | 96 | [self.tableView selectRowAtIndexPath:indexPath animated:NO scrollPosition:UITableViewScrollPositionMiddle]; 97 | } 98 | 99 | @end -------------------------------------------------------------------------------- /CJCalendar/calendar/service/CJUseTime.h: -------------------------------------------------------------------------------- 1 | // 2 | // CJUseTime.h 3 | // CJCalendar 4 | // 5 | // Created by chjsun on 16/5/26. 6 | // Copyright © 2016年 chjsun. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface CJUseTime : NSObject 12 | 13 | 14 | + (CJUseTime *)sharedInstance; 15 | /** 16 | * 根据给定字符串返回字符串代表月的天数 17 | * 18 | * @param dateStr @"xxxx-xx-xx" 19 | * 20 | * @return 28 or 29 or 30 or 31 21 | */ 22 | -(NSInteger) timeNumberOfDaysInString:(NSString *) dateStr; 23 | -(NSInteger) timeNumberOfDaysInDate:(NSDate *) date; 24 | 25 | /** 26 | * 根据给定字字符串返回字符串代表天是星期几 27 | * 28 | * @param dateStr @"xxxx-xx-xx" 29 | * 30 | * @return 0-周日 or 1-周一 or 2-周二 or 3-周三 or 4-周四 or 5-周五 or 6-周六 31 | */ 32 | -(NSInteger) timeMonthWeekDayOfFirstDay:(NSString *)dateStr; 33 | /** 34 | * 获得一个月“占”几个星期 35 | * 36 | * @param dateStr @"xxxx-xx-xx" 37 | * 38 | * @return 4 or 5 or 6 39 | */ 40 | -(NSInteger)timeFewWeekInMonth:(NSString *)dateStr; 41 | /** 42 | * 根据给定字符串返回字符串代表的农历的日 43 | * 44 | * @param dateStr @"xxxx-xx-xx" 45 | * 46 | * @return 1~30 47 | */ 48 | -(NSString *)timeChineseDaysWithDate:(NSString *)dateStr; 49 | /** 50 | * 根据给定字符串返回字符串代表的农历的日期 51 | * 52 | * @param dateStr @"xxxx-xx-xx" 53 | * 54 | * @return 丙寅虎年 四月廿四 星期三 55 | */ 56 | - (NSString *) timeChineseCalendarWithString:(NSString *)dateStr; 57 | - (NSString *) timeChineseCalendarWithDate:(NSDate *)date; 58 | 59 | // 字符串转日期 60 | - (NSDate *) strToDate:(NSString *)dateStr; 61 | // 日期转字符串 62 | - (NSString *) dataToString:(NSDate *)date; 63 | @end 64 | -------------------------------------------------------------------------------- /CJCalendar/calendar/service/CJUseTime.m: -------------------------------------------------------------------------------- 1 | // 2 | // CJUseTime.m 3 | // CJCalendar 4 | // 5 | // Created by chjsun on 16/5/26. 6 | // Copyright © 2016年 chjsun. All rights reserved. 7 | // 8 | 9 | #import "CJUseTime.h" 10 | 11 | @interface CJUseTime() 12 | 13 | /** 公历 */ 14 | @property (nonatomic, strong) NSCalendar *gregorianCalendar; 15 | /** 农历 */ 16 | @property (nonatomic, strong) NSCalendar *chineseCalendar; 17 | /** 格式化 date <--> string */ 18 | @property (nonatomic, strong) NSDateFormatter *formatter; 19 | 20 | /** 农历年 */ 21 | @property (nonatomic, strong) NSArray *chineseYears; 22 | /** 农历月 */ 23 | @property (nonatomic, strong) NSArray *chineseMonths; 24 | /** 农历日 */ 25 | @property (nonatomic, strong) NSArray *chineseDays; 26 | /** 星期 */ 27 | @property (nonatomic, strong) NSArray *chineseWeekDays; 28 | @end 29 | 30 | @implementation CJUseTime 31 | 32 | static CJUseTime * _sharedInstance = nil; 33 | 34 | +(instancetype)allocWithZone:(struct _NSZone *)zone{ 35 | if (!_sharedInstance) { 36 | _sharedInstance = [super allocWithZone:zone]; 37 | 38 | return _sharedInstance; 39 | } 40 | 41 | return nil; 42 | } 43 | 44 | + (CJUseTime *)sharedInstance { 45 | // 单例模式 46 | static dispatch_once_t onceToken; 47 | 48 | dispatch_once(&onceToken, ^{ 49 | 50 | _sharedInstance = [[CJUseTime alloc] init]; 51 | }); 52 | 53 | return _sharedInstance; 54 | } 55 | 56 | 57 | -(NSCalendar *)gregorianCalendar{ 58 | if (!_gregorianCalendar) { 59 | _gregorianCalendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian]; 60 | [_gregorianCalendar setTimeZone:[NSTimeZone timeZoneWithName:@"GMT"]]; 61 | [_gregorianCalendar setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"en_US"]]; 62 | 63 | } 64 | return _gregorianCalendar; 65 | } 66 | 67 | 68 | -(NSCalendar *)chineseCalendar{ 69 | if (!_chineseCalendar) { 70 | _chineseCalendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierChinese]; 71 | [_chineseCalendar setTimeZone:[NSTimeZone timeZoneWithName:@"GMT"]]; 72 | [_chineseCalendar setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"en_US"]]; 73 | } 74 | return _chineseCalendar; 75 | } 76 | 77 | -(NSDateFormatter *)formatter{ 78 | if (!_formatter) { 79 | _formatter = [[NSDateFormatter alloc] init]; 80 | [_formatter setTimeZone:[NSTimeZone timeZoneWithName:@"GMT"]]; 81 | [_formatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"en_US"]]; 82 | } 83 | return _formatter; 84 | } 85 | 86 | //农历年数据,加载一次足矣 87 | -(NSArray *)chineseYears{ 88 | if (!_chineseYears) { 89 | _chineseYears = [NSArray arrayWithObjects: 90 | @"甲子鼠年", @"乙丑牛年", @"丙寅虎年", @"丁卯兔年", @"戊辰龙年", @"己巳蛇年", @"庚午马年", @"辛未羊年", @"壬申猴年", @"癸酉鸡年", 91 | @"甲戌狗年", @"乙亥猪年", @"丙子鼠年", @"丁丑牛年", @"戊寅虎年", @"己卯兔年", @"庚辰龙年", @"辛己蛇年", @"壬午马年", @"癸未羊年", 92 | @"甲申猴年", @"乙酉鸡年", @"丙戌狗年", @"丁亥猪年", @"戊子鼠年", @"己丑牛年", @"庚寅虎年", @"辛卯兔年", @"壬辰龙年", @"癸巳蛇年", 93 | @"甲午马年", @"乙未羊年", @"丙申猴年", @"丁酉鸡年", @"戊戌狗年", @"己亥猪年", @"庚子鼠年", @"辛丑牛年", @"壬寅虎年", @"癸卯兔年", 94 | @"甲辰龙年", @"乙巳蛇年", @"丙午马年", @"丁未羊年", @"戊申猴年", @"己酉鸡年", @"庚戌狗年", @"辛亥猪年", @"壬子鼠年", @"癸丑牛年", 95 | @"甲寅虎年", @"乙卯兔年", @"丙辰龙年", @"丁巳蛇年", @"戊午马年", @"己未羊年", @"庚申猴年", @"辛酉鸡年", @"壬戌狗年", @"癸亥猪年", nil]; 96 | } 97 | return _chineseYears; 98 | } 99 | //农历月数据,加载一次足矣 100 | -(NSArray *)chineseMonths{ 101 | if (!_chineseMonths) { 102 | _chineseMonths = [NSArray arrayWithObjects: 103 | @"正月", @"二月", @"三月", @"四月", @"五月", @"六月", @"七月", @"八月", 104 | @"九月", @"十月", @"冬月", @"腊月", nil]; 105 | 106 | } 107 | return _chineseMonths; 108 | } 109 | //农历日数据,加载一次足矣 110 | -(NSArray *)chineseDays{ 111 | if (!_chineseDays) { 112 | _chineseDays = [NSArray arrayWithObjects: 113 | @"初一", @"初二", @"初三", @"初四", @"初五", @"初六", @"初七", @"初八", @"初九", @"初十", 114 | @"十一", @"十二", @"十三", @"十四", @"十五", @"十六", @"十七", @"十八", @"十九", @"二十", 115 | @"廿一", @"廿二", @"廿三", @"廿四", @"廿五", @"廿六", @"廿七", @"廿八", @"廿九", @"三十", nil]; 116 | } 117 | return _chineseDays; 118 | } 119 | //星期数据,加载一次足矣 120 | -(NSArray *)chineseWeekDays{ 121 | if (!_chineseWeekDays) { 122 | _chineseWeekDays = [NSArray arrayWithObjects: 123 | @"星期天", @"星期一", @"星期二", @"星期三", @"星期四", @"星期五", @"星期六", nil]; 124 | } 125 | return _chineseWeekDays; 126 | } 127 | 128 | /** 129 | * 根据给定字符串返回字符串代表月的天数 130 | * 131 | * @param dateStr @"xxxx-xx-xx" 132 | * 133 | * @return 28 or 29 or 30 or 31 134 | */ 135 | -(NSInteger) timeNumberOfDaysInString:(NSString *)dateStr{ 136 | NSDate *date = [self strToDate:dateStr]; 137 | return [self timeNumberOfDaysInDate:date]; 138 | } 139 | 140 | 141 | //获取给定日期所在月有多少天 142 | - (NSInteger)timeNumberOfDaysInDate:(NSDate *)date 143 | { 144 | // 只要个时间给日历,就会帮你计算出来。这里的时间取当前的时间。 145 | NSRange range = [self.gregorianCalendar rangeOfUnit:NSCalendarUnitDay 146 | inUnit: NSCalendarUnitMonth 147 | forDate:date]; 148 | return range.length; 149 | } 150 | 151 | -(NSInteger) timeMonthWeekDayOfFirstDay:(NSString *)dateStr{ 152 | NSDate *date = [self strToDate:dateStr]; 153 | return [self getDateInfo:date]; 154 | 155 | } 156 | 157 | //获取给定日期的详细信息,可以得到是周几 158 | - (NSInteger) getDateInfo:(NSDate *)date 159 | { 160 | // NSDateComponent 可以获得日期的详细信息,即日期的组成 161 | NSDateComponents *comps = [self.gregorianCalendar components:NSCalendarUnitWeekOfMonth|NSCalendarUnitWeekday fromDate:date]; 162 | 163 | // weekday 1 是周日,2是周一 3.以此类推 164 | return comps.weekday - 1; 165 | } 166 | 167 | // 字符串转日期 168 | - (NSDate *) strToDate:(NSString *)dateStr 169 | { 170 | [self.formatter setDateFormat:@"yyyy-MM-dd"]; // 年-月-日 时:分:秒 171 | // 这个格式可以随便定义,比如:@"yyyy,MM,dd,HH,mm,ss" 172 | return [self.formatter dateFromString:dateStr]; 173 | } 174 | 175 | // 日期转字符串 176 | - (NSString *) dataToString:(NSDate *)date 177 | { 178 | [self.formatter setDateFormat:@"yyyy-MM-dd"]; // 年-月-日 时:分:秒 179 | // 这个格式可以随便定义,比如:@"yyyy,MM,dd,HH,mm,ss" 180 | return [self.formatter stringFromDate:date]; 181 | } 182 | 183 | //获得一个月“占”几个星期 184 | -(NSInteger)timeFewWeekInMonth:(NSString *)dateStr{ 185 | 186 | NSDate *date = [self strToDate:dateStr]; 187 | //一个月多少天 188 | NSInteger dayNumber = [self timeNumberOfDaysInDate:date]; 189 | 190 | NSInteger weekday = [self getDateInfo:date]; 191 | 192 | NSInteger weeks = 0; 193 | 194 | if (weekday) { 195 | weeks += 1; 196 | dayNumber -= (7-weekday); 197 | } 198 | weeks += dayNumber/7; 199 | weeks += dayNumber % 7? 1: 0; 200 | 201 | return weeks; 202 | 203 | } 204 | 205 | // 农历--获取给定日期的详细信息,可以得到是几号 206 | - (NSInteger) timeDateOfDay:(NSString *)dateStr{ 207 | NSDate *date = [self strToDate:dateStr]; 208 | // NSDateComponent 可以获得日期的详细信息,即日期的组成 209 | NSDateComponents *comps = [self.chineseCalendar components:NSCalendarUnitDay fromDate:date]; 210 | 211 | // weekOfMonth 本日处在第几周,不足一周按一周算,最大是6周 212 | return comps.day; 213 | } 214 | 215 | /** 216 | * 根据给定字符串返回字符串代表的农历的日期 217 | * 218 | * @param dateStr @"xxxx-xx-xx" 219 | * 220 | * @return 丙寅虎年 四月廿四 星期三 221 | */ 222 | - (NSString *) timeChineseCalendarWithString:(NSString *)dateStr{ 223 | NSDate *date = [self strToDate:dateStr]; 224 | return [self timeChineseCalendarWithDate:date]; 225 | 226 | } 227 | // get Chinese calendar 228 | - (NSString *) timeChineseCalendarWithDate:(NSDate *)date{ 229 | 230 | NSInteger dayOfWeek =[self getDateInfo:date]; 231 | 232 | 233 | NSDateComponents *localeComp = [self.chineseCalendar components:NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay fromDate:date]; 234 | 235 | NSString *y_str = [self.chineseYears objectAtIndex:localeComp.year-1]; 236 | NSString *m_str = [self.chineseMonths objectAtIndex:localeComp.month-1]; 237 | NSString *d_str = [self.chineseDays objectAtIndex:(localeComp.day==0? 29: localeComp.day-1)]; 238 | NSString *dw_str = [self.chineseWeekDays objectAtIndex:dayOfWeek]; 239 | 240 | return [NSString stringWithFormat:@"%@ %@%@ %@", y_str, m_str, d_str, dw_str]; 241 | } 242 | 243 | /** 244 | * 根据给定字符串返回字符串代表的农历的日 245 | * 246 | * @param dateStr @"xxxx-xx-xx" 247 | * 248 | * @return 1~30 249 | */ 250 | 251 | -(NSString *)timeChineseDaysWithDate:(NSString *)dateStr{ 252 | NSDate *date = [self strToDate:dateStr]; 253 | return [self getChineseWeekDaysWithDate:date]; 254 | } 255 | 256 | // get chinese day 257 | -(NSString *)getChineseWeekDaysWithDate:(NSDate *)date{ 258 | 259 | NSDateComponents *localeComp = [self.chineseCalendar components: NSCalendarUnitDay fromDate:date]; 260 | 261 | return [self.chineseDays objectAtIndex:(localeComp.day==0? 29: localeComp.day-1)]; 262 | } 263 | 264 | 265 | 266 | 267 | @end 268 | -------------------------------------------------------------------------------- /CJCalendar/calendar/view/CJDecisionView.h: -------------------------------------------------------------------------------- 1 | // 2 | // CJDecisionView.h 3 | // CJCalendar 4 | // 5 | // Created by chjsun on 16/5/25. 6 | // Copyright © 2016年 chjsun. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @class CJDecisionView; 12 | @protocol DecisionDelegate 13 | 14 | @optional 15 | -(void) DecisionDidSelectNow: (CJDecisionView *)decision; 16 | 17 | -(void) DecisionDidSelectCancel: (CJDecisionView *)decision; 18 | 19 | -(void) DecisionDidSelectAction: (CJDecisionView *)decision; 20 | 21 | @end 22 | 23 | @interface CJDecisionView : UIView 24 | 25 | //初始化 26 | -(void) generateDecision; 27 | 28 | /** 代理 */ 29 | @property (nonatomic, assign) id delegate; 30 | 31 | /** 按钮文字颜色 */ 32 | @property (nonatomic, copy) UIColor *textColor; 33 | /** 点击按钮文字颜色 */ 34 | @property (nonatomic, copy) UIColor *selectColor; 35 | @end 36 | -------------------------------------------------------------------------------- /CJCalendar/calendar/view/CJDecisionView.m: -------------------------------------------------------------------------------- 1 | // 2 | // CJDecisionView.m 3 | // CJCalendar 4 | // 5 | // Created by chjsun on 16/5/25. 6 | // Copyright © 2016年 chjsun. All rights reserved. 7 | // 8 | 9 | #import "CJDecisionView.h" 10 | 11 | #define CJColor(r, g, b) ([UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:1]) 12 | 13 | @implementation CJDecisionView 14 | 15 | 16 | -(instancetype)initWithFrame:(CGRect)frame{ 17 | if (self = [super initWithFrame:frame]) { 18 | self.textColor = CJColor(71, 55, 169); 19 | self.selectColor = CJColor(30, 25, 70); 20 | } 21 | return self; 22 | } 23 | 24 | 25 | -(void) generateDecision{ 26 | CGFloat width = self.frame.size.width/4; 27 | CGFloat height = self.frame.size.height; 28 | 29 | // 返回当前 30 | CGRect nowRect = CGRectMake(0, 0, width, height); 31 | [self addNow:nowRect]; 32 | // 取消 33 | CGRect cancelRect = CGRectMake(width * 2, 0, width, height); 34 | [self addCancel:cancelRect]; 35 | // 确定 36 | CGRect actionRect = CGRectMake(width * 3, 0, width, height); 37 | [self addAction:actionRect]; 38 | 39 | } 40 | // 返回当前 41 | -(void) addNow:(CGRect)rect{ 42 | 43 | UIButton *now = [[UIButton alloc] initWithFrame:rect]; 44 | [now setTitle:@"今日" forState:UIControlStateNormal]; 45 | now.titleLabel.font = [UIFont systemFontOfSize:15]; 46 | [now setTitleColor:self.textColor forState:UIControlStateNormal]; 47 | [now setTitleColor:self.selectColor forState:UIControlStateHighlighted]; 48 | 49 | [now addTarget:self action:@selector(didNow:) forControlEvents:UIControlEventTouchDown]; 50 | 51 | [self addSubview:now]; 52 | } 53 | // 返回按钮点击事件 54 | -(void) didNow:(UIButton *)button{ 55 | 56 | if ([self.delegate respondsToSelector:@selector(DecisionDidSelectNow:)]) { 57 | [self.delegate DecisionDidSelectNow:self]; 58 | } 59 | 60 | } 61 | 62 | 63 | // 取消 64 | -(void) addCancel:(CGRect)rect{ 65 | 66 | UIButton *cancel = [[UIButton alloc] initWithFrame:rect]; 67 | [cancel setTitle:@"取消" forState:UIControlStateNormal]; 68 | [cancel setTitleColor:self.textColor forState:UIControlStateNormal]; 69 | [cancel setTitleColor:self.selectColor forState:UIControlStateHighlighted]; 70 | cancel.titleLabel.font = [UIFont systemFontOfSize:15]; 71 | 72 | [cancel addTarget:self action:@selector(didCancel:) forControlEvents:UIControlEventTouchDown]; 73 | 74 | [self addSubview:cancel]; 75 | } 76 | 77 | // 取消按钮点击事件 78 | -(void) didCancel:(UIButton *)button{ 79 | 80 | if ([self.delegate respondsToSelector:@selector(DecisionDidSelectCancel:)]) { 81 | [self.delegate DecisionDidSelectCancel:self]; 82 | } 83 | } 84 | 85 | 86 | // 确定 87 | -(void) addAction:(CGRect)rect{ 88 | 89 | UIButton *action = [[UIButton alloc] initWithFrame:rect]; 90 | [action setTitle:@"确定" forState:UIControlStateNormal]; 91 | [action setTitleColor:self.textColor forState:UIControlStateNormal]; 92 | [action setTitleColor:self.selectColor forState:UIControlStateHighlighted]; 93 | action.titleLabel.font = [UIFont systemFontOfSize:15]; 94 | 95 | [action addTarget:self action:@selector(didAction:) forControlEvents:UIControlEventTouchDown]; 96 | 97 | [self addSubview:action]; 98 | } 99 | 100 | // 确定按钮点击事件 101 | -(void) didAction:(UIButton *)button{ 102 | 103 | if ([self.delegate respondsToSelector:@selector(DecisionDidSelectAction:)]) { 104 | [self.delegate DecisionDidSelectAction:self]; 105 | } 106 | } 107 | 108 | 109 | @end 110 | -------------------------------------------------------------------------------- /CJCalendar/calendar/view/CJMonthDayCollectionCell.h: -------------------------------------------------------------------------------- 1 | // 2 | // CJMonthDayCollectionCell.h 3 | // CJCalendar 4 | // 5 | // Created by chjsun on 16/5/26. 6 | // Copyright © 2016年 chjsun. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface CJMonthDayCollectionCell : UICollectionViewCell 12 | 13 | /** 月 */ 14 | @property (nonatomic, copy) NSString *gregoiainDay; 15 | /** 日 */ 16 | @property (nonatomic, copy) NSString *lunarDay; 17 | 18 | /** 阳历 */ 19 | @property (nonatomic, copy) NSString *gregoiainCalendar; 20 | /** 农历 */ 21 | @property (nonatomic, copy) NSString *chineseCalendar; 22 | 23 | @end 24 | -------------------------------------------------------------------------------- /CJCalendar/calendar/view/CJMonthDayCollectionCell.m: -------------------------------------------------------------------------------- 1 | // 2 | // CJMonthDayCollectionCell.m 3 | // CJCalendar 4 | // 5 | // Created by chjsun on 16/5/26. 6 | // Copyright © 2016年 chjsun. All rights reserved. 7 | // 8 | 9 | #import "CJMonthDayCollectionCell.h" 10 | 11 | @interface CJMonthDayCollectionCell() 12 | 13 | @property (weak, nonatomic) IBOutlet UILabel *gregoiainDaylabel; 14 | 15 | @property (weak, nonatomic) IBOutlet UILabel *lunarDayLabel; 16 | 17 | @end 18 | 19 | @implementation CJMonthDayCollectionCell 20 | 21 | - (void)awakeFromNib { 22 | // Initialization code 23 | [super awakeFromNib]; 24 | } 25 | 26 | -(void)setGregoiainDay:(NSString *)gregoiainDay{ 27 | _gregoiainDay = gregoiainDay; 28 | self.gregoiainDaylabel.text = gregoiainDay; 29 | } 30 | 31 | -(void)setLunarDay:(NSString *)lunarDay{ 32 | _lunarDay = lunarDay; 33 | self.lunarDayLabel.text = lunarDay; 34 | } 35 | 36 | 37 | -(instancetype)initWithFrame:(CGRect)frame{ 38 | 39 | self = [super initWithFrame:frame]; 40 | 41 | if (self) { 42 | 43 | // 在此添加 44 | // 初始化时加载collectionCell.xib文件 45 | 46 | NSArray *arrayOfViews = [[NSBundle mainBundle] loadNibNamed:@"CJMonthDayCollectionCell" owner:self options:nil]; 47 | 48 | // 如果路径不存在,return nil 49 | 50 | if(arrayOfViews.count < 1){return nil;} 51 | // 如果xib中view不属于UICollectionViewCell类,return nil 52 | if(![[arrayOfViews objectAtIndex:0] isKindOfClass:[UICollectionViewCell class]]){ 53 | return nil; 54 | } 55 | // 加载nib 56 | self = [arrayOfViews objectAtIndex:0]; 57 | } 58 | return self; 59 | } 60 | 61 | 62 | @end 63 | -------------------------------------------------------------------------------- /CJCalendar/calendar/view/CJMonthDayCollectionCell.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 22 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /CJCalendar/calendar/view/CJSelectTimeScrollView.h: -------------------------------------------------------------------------------- 1 | // 2 | // CJSelectTime.h 3 | // CJCalendar 4 | // 5 | // Created by chjsun on 16/5/29. 6 | // Copyright © 2016年 chjsun. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @class CJSelectTimeScrollView; 12 | @protocol SelectTimeScrollViewDelegate 13 | 14 | @optional 15 | -(void) selectTimeView:(CJSelectTimeScrollView *)timeScroll didSelectYearAtIndexPath:(NSIndexPath *)indexPath cellText:(NSString *)cellText; 16 | 17 | -(void) selectTimeView:(CJSelectTimeScrollView *)timeScroll didSelectMonthAndDayAtIndexPath:(NSIndexPath *)indexPath GregoiainCalendar:(NSString *)gregoiainCalendar chineseCalendar:(NSString *)chineseCalendar; 18 | 19 | @end 20 | 21 | @interface CJSelectTimeScrollView : UIScrollView 22 | 23 | // attr 24 | /** 需要设置的年 */ 25 | @property (nonatomic, copy) NSString *year; 26 | /** 需要设置的月 */ 27 | @property (nonatomic, copy) NSString *month; 28 | /** 需要设置的日 */ 29 | @property (nonatomic, copy) NSString *day; 30 | 31 | /** 选中状态下的年的背景颜色 */ 32 | @property (nonatomic, strong) UIColor *selectYearColor; 33 | /** 选中状态下的,年的背景颜色 */ 34 | @property (nonatomic, strong) UIColor *selectMonthDayColor; 35 | 36 | // methed 37 | // 设置所有的控制器 38 | -(void) setUpAllControllerWithSuperControll:(UIViewController *)controller; 39 | //根据时间更新collection 40 | -(void)refreshControlWithYear:(NSString *)year month:(NSString *)month day:(NSString *)day; 41 | 42 | 43 | /** 代理 */ 44 | @property (nonatomic, assign) id delegates; 45 | 46 | @end 47 | -------------------------------------------------------------------------------- /CJCalendar/calendar/view/CJSelectTimeScrollView.m: -------------------------------------------------------------------------------- 1 | // 2 | // CJSelectTime.m 3 | // CJCalendar 4 | // 5 | // Created by chjsun on 16/5/29. 6 | // Copyright © 2016年 chjsun. All rights reserved. 7 | // 8 | 9 | #import "CJSelectTimeScrollView.h" 10 | 11 | #import "CJYearViewController.h" 12 | #import "CJMonthDayViewController.h" 13 | 14 | #define CJColor(r, g, b) ([UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:1]) 15 | 16 | #define CJEdgeWidth 40 17 | #define CJEdgeHeight 50 18 | 19 | @interface CJSelectTimeScrollView() 20 | 21 | /** 控制器宽度 */ 22 | @property (nonatomic, assign) CGFloat nextWidth; 23 | 24 | /** selectController */ 25 | @property (nonatomic, assign) CJYearViewController *yearController; 26 | 27 | /** selectController */ 28 | @property (nonatomic, assign) CJMonthDayViewController *monthAndDayController; 29 | 30 | @end 31 | 32 | 33 | @implementation CJSelectTimeScrollView 34 | 35 | #pragma mark - 设置滚动的scrollView 36 | /** 37 | * 设置可以滚动的控制器 38 | */ 39 | -(void) setUpAllControllerWithSuperControll:(UIViewController *)controller{ 40 | // 设置月、日 41 | [self setUpMonthAndDayWithSuperController:controller]; 42 | // 设置年 43 | [self setUpYearWithSuperController:controller]; 44 | 45 | // 添加scrollView颜色 46 | self.backgroundColor = [UIColor whiteColor]; 47 | } 48 | 49 | // 设置选择年的table控制器 50 | -(void) setUpYearWithSuperController:(UIViewController *)superController{ 51 | 52 | CJYearViewController *year = [[CJYearViewController alloc] init]; 53 | self.yearController = year; 54 | year.delegate = self; 55 | 56 | CGFloat selectWidth = self.bounds.size.width; 57 | CGFloat selectHeight = self.bounds.size.height; 58 | 59 | year.view.frame = CGRectMake(self.nextWidth, 0, selectWidth, selectHeight); 60 | [self addSubview:year.view]; 61 | [superController addChildViewController:year]; 62 | year.selectColor = CJColor(60, 45, 140); 63 | 64 | self.nextWidth += selectWidth; 65 | } 66 | 67 | // 设置选择日子的collection控制器 68 | -(void) setUpMonthAndDayWithSuperController:(UIViewController *)superController{ 69 | 70 | CGFloat selectWidth = self.bounds.size.width; 71 | CGFloat selectHeight = self.bounds.size.height; 72 | CGRect selectRect = CGRectMake(self.nextWidth, 0, selectWidth, selectHeight); 73 | CJMonthDayViewController *monthAndDay = [[CJMonthDayViewController alloc] initWithFrame:selectRect]; 74 | monthAndDay.delegate = self; 75 | self.monthAndDayController = monthAndDay; 76 | [self addSubview:monthAndDay.view]; 77 | [superController addChildViewController:monthAndDay]; 78 | self.nextWidth += selectWidth; 79 | monthAndDay.selectColor = CJColor(60, 45, 140); 80 | } 81 | 82 | 83 | #pragma mark - 刷新方法 84 | // 刷新年 85 | -(void)setYear:(NSString *)year{ 86 | _year = year; 87 | [self.yearController refreshControlWithCellText:year]; 88 | } 89 | 90 | // 刷新日历 91 | -(void)refreshControlWithYear:(NSString *)year month:(NSString *)month day:(NSString *)day{ 92 | [self.monthAndDayController refreshControlWithYear:year month:month day:day]; 93 | } 94 | 95 | 96 | #pragma mark - 年份选择控制板 yearDelegate 97 | -(void)yearTableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath cellText:(NSString *)cellText{ 98 | 99 | if ([self.delegates respondsToSelector:@selector(selectTimeView:didSelectYearAtIndexPath:cellText:)]) { 100 | [self.delegates selectTimeView:self didSelectYearAtIndexPath:indexPath cellText:cellText]; 101 | } 102 | } 103 | 104 | #pragma mark - 日期选择控制器 105 | -(void)monthAndDayController:(CJMonthDayViewController *)controller didSelectIndexPath:(NSIndexPath *)indexPath GregoiainCalendar:(NSString *)gregoiainCalendar chineseCalendar:(NSString *)chineseCalendar{ 106 | if ([self.delegates respondsToSelector:@selector(selectTimeView:didSelectMonthAndDayAtIndexPath:GregoiainCalendar:chineseCalendar:)]) { 107 | 108 | [self.delegates selectTimeView:self didSelectMonthAndDayAtIndexPath:indexPath GregoiainCalendar:gregoiainCalendar chineseCalendar:chineseCalendar]; 109 | } 110 | } 111 | 112 | -(void)setSelectYearColor:(UIColor *)selectYearColor{ 113 | _selectYearColor = selectYearColor; 114 | self.yearController.selectColor = selectYearColor; 115 | } 116 | 117 | -(void)setSelectMonthDayColor:(UIColor *)selectMonthDayColor{ 118 | _selectMonthDayColor = selectMonthDayColor; 119 | self.monthAndDayController.selectColor = selectMonthDayColor; 120 | } 121 | 122 | @end 123 | -------------------------------------------------------------------------------- /CJCalendar/calendar/view/CJShowTimeView.h: -------------------------------------------------------------------------------- 1 | // 2 | // CJShowTimeView.h 3 | // CJCalendar 4 | // 5 | // Created by chjsun on 16/5/23. 6 | // Copyright © 2016年 chjsun. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @class CJShowTimeView; 12 | @protocol ShowTimeViewDelegate 13 | 14 | @optional 15 | //点击月日的时候调用 16 | -(void)ShowTimeView:(CJShowTimeView *)timeView didSelectYear:(NSString *)year Month:(NSString *)month day:(NSString *)day; 17 | 18 | //点击年的时候调用 19 | -(void)ShowTimeView:(CJShowTimeView *)timeView didSelectYear:(NSString *)year; 20 | 21 | @end 22 | 23 | @interface CJShowTimeView : UIView 24 | 25 | //以下属性均有默认值 26 | /** HeaderName 头部的标题 */ 27 | @property (nonatomic, copy) NSString *headerName; 28 | /** HeaderColor 头部标题的颜色*/ 29 | @property (nonatomic, strong) UIColor *headerColor; 30 | /** HeaderBackgroundColor 头部标题栏背景颜色*/ 31 | @property (nonatomic, strong) UIColor *headerBackgroundColor; 32 | 33 | /** contentColor 头部内容文本颜色*/ 34 | @property (nonatomic, strong) UIColor *contentColor; 35 | /** contentBackgroundColor 头部内容背景颜色*/ 36 | @property (nonatomic, strong) UIColor *contentBackgroundColor; 37 | /** month 月份值*/ 38 | @property (nonatomic, copy) NSString *monthText; 39 | /** day 日期值*/ 40 | @property (nonatomic, copy) NSString *dayText; 41 | /** year 年份值*/ 42 | @property (nonatomic, copy) NSString *yearText; 43 | 44 | /** basicColor 未选中状态时文本颜色*/ 45 | @property (nonatomic, strong) UIColor *basicColor; 46 | 47 | /** 代理 */ 48 | @property (nonatomic, assign) id delegate; 49 | 50 | -(void) generateView; 51 | 52 | @end 53 | -------------------------------------------------------------------------------- /CJCalendar/calendar/view/CJShowTimeView.m: -------------------------------------------------------------------------------- 1 | // 2 | // CJShowTimeView.m 3 | // CJCalendar 4 | // 5 | // Created by chjsun on 16/5/23. 6 | // Copyright © 2016年 chjsun. All rights reserved. 7 | // 8 | 9 | //练习英文注释 不到之处 敬请谅解 10 | #import "CJShowTimeView.h" 11 | 12 | #define CJColor(r, g, b) ([UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:1]) 13 | 14 | #define CJBasicFontToHeight 0.83 15 | #define CJSelectAlpha 0.6 16 | 17 | @interface CJShowTimeView() 18 | 19 | /** title */ 20 | @property (nonatomic, strong) UILabel *titleLabel; 21 | /** month */ 22 | @property (nonatomic, strong) UILabel *animMonthLabel; 23 | /** day */ 24 | @property (nonatomic, strong) UILabel *animDayLabel; 25 | /** year */ 26 | @property (nonatomic, strong) UILabel *animYearLabel; 27 | 28 | /** headerView */ 29 | @property (nonatomic, strong) UIView *headerView; 30 | /** monthAndDayView */ 31 | @property (nonatomic, strong) UIView *monthAndDayView; 32 | /** yearView */ 33 | @property (nonatomic, strong) UIView *yearView; 34 | 35 | @end 36 | 37 | @implementation CJShowTimeView 38 | 39 | /** 40 | * 标题懒加载 41 | * 42 | * @return label 43 | */ 44 | -(UILabel *)titleLabel{ 45 | if (!_titleLabel) { 46 | _titleLabel = [[UILabel alloc] init]; 47 | } 48 | return _titleLabel; 49 | } 50 | 51 | /** 52 | * 月份懒加载 53 | * 54 | * @return label 55 | */ 56 | -(UILabel *)animMonthLabel{ 57 | if (!_animMonthLabel) { 58 | _animMonthLabel = [[UILabel alloc] init]; 59 | _animMonthLabel.textColor = self.contentColor; 60 | } 61 | return _animMonthLabel; 62 | } 63 | /** 64 | * 日期懒加载 65 | * 66 | * @return label 67 | */ 68 | -(UILabel *)animDayLabel{ 69 | if (!_animDayLabel) { 70 | _animDayLabel = [[UILabel alloc] init]; 71 | _animDayLabel.textColor = self.contentColor; 72 | } 73 | return _animDayLabel; 74 | } 75 | /** 76 | * 年份懒加载 77 | * 78 | * @return label 79 | */ 80 | -(UILabel *)animYearLabel{ 81 | if (!_animYearLabel) { 82 | _animYearLabel = [[UILabel alloc] init]; 83 | _animYearLabel.textColor = self.contentColor; 84 | } 85 | return _animYearLabel; 86 | } 87 | 88 | /** 89 | * 视图窗口懒加载 90 | * 91 | * @return 视图 92 | */ 93 | -(UIView *)headerView{ 94 | if (!_headerView) { 95 | _headerView = [[UIView alloc] init]; 96 | } 97 | return _headerView; 98 | 99 | } 100 | /** 101 | * 视图窗口懒加载 102 | * 103 | * @return 视图 104 | */ 105 | -(UIView *)monthAndDayView{ 106 | if (!_monthAndDayView) { 107 | _monthAndDayView = [[UIView alloc] init]; 108 | } 109 | return _monthAndDayView; 110 | 111 | } 112 | /** 113 | * 视图窗口懒加载 114 | * 115 | * @return 视图 116 | */ 117 | -(UIView *)yearView{ 118 | if (!_yearView) { 119 | _yearView = [[UIView alloc] init]; 120 | } 121 | return _yearView; 122 | 123 | } 124 | 125 | 126 | -(instancetype)initWithFrame:(CGRect)frame{ 127 | 128 | if (self = [super initWithFrame:frame]) { 129 | //set default attr 130 | self.headerName = @"己酉鸡年 冬月廿四 星期一"; 131 | self.headerBackgroundColor = CJColor(60, 45, 140); 132 | self.headerColor = [UIColor whiteColor]; 133 | 134 | self.contentBackgroundColor = CJColor(71, 55, 169); 135 | self.contentColor = [UIColor whiteColor]; 136 | self.dayText = @"1"; 137 | self.monthText = @"1"; 138 | self.yearText = @"1970"; 139 | 140 | } 141 | return self; 142 | } 143 | 144 | -(void) generateView{ 145 | //set header 146 | CGRect headerRect = CGRectMake(0, 0, self.bounds.size.width, 22); 147 | [self generateHeaderView:headerRect]; 148 | 149 | //set content 150 | CGFloat contentHeight = self.bounds.size.height - 22; 151 | CGRect contentRect = CGRectMake(0, 22, self.bounds.size.width, contentHeight); 152 | [self generateContentView:contentRect]; 153 | } 154 | 155 | /** 156 | * set HeaderView 157 | * 158 | * @param rect headerViewFrame 159 | */ 160 | -(void) generateHeaderView:(CGRect)rect{ 161 | 162 | self.headerView.frame = rect; 163 | self.headerView.backgroundColor = self.headerBackgroundColor; 164 | 165 | [self.headerView addSubview:self.titleLabel]; 166 | self.titleLabel.text = self.headerName; 167 | self.titleLabel.textColor = self.headerColor; 168 | self.titleLabel.font = [UIFont boldSystemFontOfSize:rect.size.height * CJBasicFontToHeight-4]; 169 | 170 | [self.titleLabel sizeToFit]; 171 | self.titleLabel.center = self.headerView.center; 172 | 173 | [self addSubview:self.headerView]; 174 | } 175 | 176 | 177 | -(void) generateContentView:(CGRect)rect{ 178 | 179 | //set month and day 180 | [self setMonthAndDay:rect]; 181 | 182 | // //set year 183 | [self setYear:rect]; 184 | } 185 | 186 | /** 187 | * set month and day 188 | * 189 | * @param rect 190 | */ 191 | -(void)setMonthAndDay:(CGRect)rect{ 192 | 193 | CGFloat smallestUnitHeight = rect.size.height/4; 194 | //set month and day 195 | CGRect monthAndDayRect = CGRectMake(rect.origin.x, 196 | rect.origin.y, 197 | rect.size.width, 198 | smallestUnitHeight * 3); 199 | 200 | self.monthAndDayView.frame = monthAndDayRect; 201 | 202 | self.monthAndDayView.backgroundColor = self.contentBackgroundColor; 203 | //set month 204 | [self.monthAndDayView addSubview:self.animMonthLabel]; 205 | 206 | self.animMonthLabel.textColor = self.contentColor; 207 | 208 | self.animMonthLabel.font = [UIFont systemFontOfSize:smallestUnitHeight * CJBasicFontToHeight]; 209 | 210 | [self.animMonthLabel sizeToFit]; 211 | //设置宽度与控件等宽 212 | CGRect monthLabelRect = CGRectMake(self.animMonthLabel.frame.origin.x, 0, rect.size.width, self.animMonthLabel.frame.size.height); 213 | self.animMonthLabel.frame = monthLabelRect; 214 | // 215 | 216 | self.animMonthLabel.textAlignment = NSTextAlignmentCenter; 217 | 218 | //set day 219 | [self.monthAndDayView addSubview:self.animDayLabel]; 220 | 221 | self.animDayLabel.text = self.dayText; 222 | self.animDayLabel.textColor = self.contentColor; 223 | self.animDayLabel.font = [UIFont systemFontOfSize:smallestUnitHeight * 2]; 224 | [self.animDayLabel sizeToFit]; 225 | 226 | //设置宽度与控件等宽 227 | 228 | CGRect dayLabelRect = CGRectMake(self.animDayLabel.frame.origin.x, CGRectGetMaxY(self.animMonthLabel.frame) , rect.size.width, self.animDayLabel.frame.size.height); 229 | self.animDayLabel.frame = dayLabelRect; 230 | // 231 | self.animDayLabel.textAlignment = NSTextAlignmentCenter; 232 | 233 | [self.monthAndDayView addSubview:self.animDayLabel]; 234 | 235 | [self addSubview:self.monthAndDayView]; 236 | 237 | //set tap UITapGestureRecognizer 238 | UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(monthAndDayTap)]; 239 | [self.monthAndDayView addGestureRecognizer:tap]; 240 | 241 | } 242 | 243 | -(void)monthAndDayTap{ 244 | //代理传值 245 | if ([_delegate respondsToSelector:@selector(ShowTimeView:didSelectYear:Month:day:)]) { 246 | [_delegate ShowTimeView:self didSelectYear:_yearText Month:_monthText day:_dayText]; 247 | } 248 | [UIView animateWithDuration:0.25 animations:^{ 249 | //动画变小 250 | _animMonthLabel.transform = CGAffineTransformMakeScale(0.8, 0.8); 251 | _animDayLabel.transform = CGAffineTransformMakeScale(0.8, 0.8); 252 | 253 | //set select color 254 | _animMonthLabel.alpha = 1; 255 | _animDayLabel.alpha = 1; 256 | _animYearLabel.alpha = CJSelectAlpha; 257 | 258 | }completion:^(BOOL finished) { 259 | // 变小之后弹性回归 260 | [UIView animateWithDuration:0.8 delay:0 usingSpringWithDamping:0.3 initialSpringVelocity:0 options:UIViewAnimationOptionCurveEaseIn animations:^{ 261 | _animMonthLabel.transform = CGAffineTransformIdentity; 262 | _animDayLabel.transform = CGAffineTransformIdentity; 263 | 264 | } completion:nil]; 265 | }]; 266 | 267 | } 268 | 269 | /** 270 | * set year 271 | * 272 | * @param rect 273 | */ 274 | -(void)setYear:(CGRect)rect{ 275 | CGFloat smallestUnitHeight = rect.size.height/4; 276 | 277 | CGRect yearRect = CGRectMake(rect.origin.x, 278 | rect.origin.y + rect.size.height/4 * 3, 279 | rect.size.width, 280 | smallestUnitHeight); 281 | 282 | self.yearView.frame = yearRect; 283 | self.yearView.backgroundColor = self.contentBackgroundColor; 284 | 285 | [self.yearView addSubview:self.animYearLabel]; 286 | //初始化透明度 287 | self.animYearLabel.alpha = CJSelectAlpha; 288 | 289 | self.animYearLabel.text = self.yearText; 290 | self.animYearLabel.textColor = self.contentColor; 291 | self.animYearLabel.font = [UIFont systemFontOfSize:smallestUnitHeight * CJBasicFontToHeight]; 292 | 293 | [self.animYearLabel sizeToFit]; 294 | //设置宽度与控件等宽 295 | CGRect yearLabelRect = CGRectMake(self.animYearLabel.frame.origin.x, 0, rect.size.width, self.animYearLabel.frame.size.height); 296 | self.animYearLabel.frame = yearLabelRect; 297 | // 298 | self.animYearLabel.textAlignment = NSTextAlignmentCenter; 299 | 300 | [self addSubview:self.yearView]; 301 | 302 | //set tap UITapGestureRecognizer 303 | UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(yearTap)]; 304 | [self.yearView addGestureRecognizer:tap]; 305 | 306 | } 307 | 308 | -(void)yearTap{ 309 | //代理传值 310 | if ([_delegate respondsToSelector:@selector(ShowTimeView:didSelectYear:)]) { 311 | [_delegate ShowTimeView:self didSelectYear:_yearText]; 312 | } 313 | [UIView animateWithDuration:0.25 animations:^{ 314 | // 动画变小 315 | _animYearLabel.transform = CGAffineTransformMakeScale(0.8, 0.8); 316 | 317 | // set select color 318 | _animMonthLabel.alpha = CJSelectAlpha; 319 | _animDayLabel.alpha = CJSelectAlpha; 320 | _animYearLabel.alpha = 1; 321 | 322 | 323 | }completion:^(BOOL finished) { 324 | // 变小之后弹性回归 325 | [UIView animateWithDuration:0.8 delay:0 usingSpringWithDamping:0.3 initialSpringVelocity:0 options:UIViewAnimationOptionCurveEaseIn animations:^{ 326 | _animYearLabel.transform = CGAffineTransformIdentity; 327 | 328 | } completion:nil]; 329 | }]; 330 | } 331 | 332 | 333 | -(void)setYearText:(NSString *)yearText{ 334 | _yearText = yearText; 335 | self.animYearLabel.text = yearText; 336 | [self setNeedsDisplay]; 337 | } 338 | 339 | -(void)setDayText:(NSString *)dayText{ 340 | _dayText = dayText; 341 | self.animDayLabel.text = [NSString stringWithFormat:@"%.2ld", (long)[dayText integerValue]]; 342 | } 343 | 344 | -(void)setMonthText:(NSString *)monthText{ 345 | _monthText = monthText; 346 | self.animMonthLabel.text = [NSString stringWithFormat:@"%ld月", (long)[monthText integerValue]]; 347 | } 348 | 349 | -(void)setHeaderName:(NSString *)headerName{ 350 | _headerName = headerName; 351 | self.titleLabel.text = headerName; 352 | } 353 | 354 | #pragma mark - 设置扩展属性 颜色 355 | 356 | - (void)setHeaderColor:(UIColor *)headerColor{ 357 | _headerColor = headerColor; 358 | self.titleLabel.textColor = headerColor; 359 | } 360 | 361 | -(void)setHeaderBackgroundColor:(UIColor *)headerBackgroundColor{ 362 | _headerBackgroundColor = headerBackgroundColor; 363 | self.headerView.backgroundColor = headerBackgroundColor; 364 | } 365 | 366 | - (void)setContentColor:(UIColor *)contentColor{ 367 | _contentColor = contentColor; 368 | self.animMonthLabel.textColor = contentColor; 369 | self.animDayLabel.textColor = contentColor; 370 | self.animYearLabel.textColor = contentColor; 371 | } 372 | 373 | - (void)setContentBackgroundColor:(UIColor *)contentBackgroundColor{ 374 | _contentBackgroundColor = contentBackgroundColor; 375 | self.monthAndDayView.backgroundColor = contentBackgroundColor; 376 | self.yearView.backgroundColor = contentBackgroundColor; 377 | } 378 | 379 | @end 380 | -------------------------------------------------------------------------------- /CJCalendar/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // CJCalendar 4 | // 5 | // Created by chjsun on 16/5/23. 6 | // Copyright © 2016年 chjsun. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /CJCalendarTests/CJCalendarTests.m: -------------------------------------------------------------------------------- 1 | // 2 | // CJCalendarTests.m 3 | // CJCalendarTests 4 | // 5 | // Created by chjsun on 16/5/23. 6 | // Copyright © 2016年 chjsun. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface CJCalendarTests : XCTestCase 12 | 13 | @end 14 | 15 | @implementation CJCalendarTests 16 | 17 | - (void)setUp { 18 | [super setUp]; 19 | // Put setup code here. This method is called before the invocation of each test method in the class. 20 | } 21 | 22 | - (void)tearDown { 23 | // Put teardown code here. This method is called after the invocation of each test method in the class. 24 | [super tearDown]; 25 | } 26 | 27 | - (void)testExample { 28 | // This is an example of a functional test case. 29 | // Use XCTAssert and related functions to verify your tests produce the correct results. 30 | } 31 | 32 | - (void)testPerformanceExample { 33 | // This is an example of a performance test case. 34 | [self measureBlock:^{ 35 | // Put the code you want to measure the time of here. 36 | }]; 37 | } 38 | 39 | @end 40 | -------------------------------------------------------------------------------- /CJCalendarTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2016 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # CJCalendar 2 | 3 | ## 这是一个可以显示农历和公历的日历控制器 4 | 5 | ![image](https://github.com/chjsun/readmeImage/blob/master/CJCalendar/modal.gif) 6 | 7 | ![image](https://github.com/chjsun/readmeImage/blob/master/CJCalendar/selecttitle.gif) 8 | 9 | ![image](https://github.com/chjsun/readmeImage/blob/master/CJCalendar/chuanzhi.gif) 10 | 11 | 使用这个日历灰常简单 12 | 只要把calendar拖到你的项目中,就可以直接用了 13 | 14 | ### 步骤: 15 | #### 一 初始化 16 | 17 | 初始化控制器,代理监听,设置大小 18 | ``` 19 | CJCalendarViewController *calendarController = [[CJCalendarViewController alloc] init]; 20 |  calendarController.view.frame = self.view.frame;// 显示底层controller 21 |  calendarController.delegate = self; 22 | 23 | ``` 24 | #### 二 添加控制器 25 | ``` 26 | [self presentViewController:calendarController animated:YES completion:nil]; 27 | ``` 28 | 29 | #### 三 实现代理方法 30 | 31 | 可选代理方法,用来接受返回的年月日 32 | ``` 33 | -(void)CalendarViewController:(CJCalendarViewController *)controller didSelectActionYear:(NSString *)year month:(NSString *)month day:(NSString *)day; 34 | ``` 35 | 36 | ### 可选的方法/属性 37 | #### 一 指定初始时间 38 | 默认不指定就是当前时间 39 | 40 | ``` 41 | /** 直接指定时间 */ 42 | @property (nonatomic, strong) NSDate *Date; 43 | /** 传入年、月、日 ,设置时间 */ 44 | -(void) setYear:(NSString *)year month:(NSString *)month day:(NSString *)day; 45 | 46 | ``` 47 | #### 二 指定颜色 48 | 49 | ``` 50 | //以下属性均有默认值 51 | /** HeaderColor default white 上部显示区域标题的颜色*/ 52 | @property (nonatomic, copy) UIColor *headerColor; 53 | /** HeaderBackgroundColor default rgb (60, 45, 140) 上部显示区域标题栏背景颜色 */ 54 | @property (nonatomic, copy) UIColor *headerBackgroundColor; 55 | /** contentColor default white 上部显示区域内容文本颜色*/ 56 | @property (nonatomic, copy) UIColor *contentColor; 57 | /** contentBackgroundColor default rgb (71, 55, 169) 上部显示区域内容背景颜色*/ 58 | @property (nonatomic, copy) UIColor *contentBackgroundColor; 59 | 60 | ``` 61 | 例如 62 | ``` 63 | calendarController.headerBackgroundColor = [UIColor purpleColor]; 64 | calendarController.headerColor = [UIColor whiteColor]; 65 | calendarController.contentColor = [UIColor whiteColor]; 66 | calendarController.contentBackgroundColor = [UIColor purpleColor]; 67 | ``` 68 | #### 三 制定背景色和透明度 69 | 默认透明度0.8 黑色 (ios8+) 70 | ``` 71 | -(void) setBgAlpha:(CGFloat)alpha color:(UIColor *)bgColor; 72 | ``` 73 | 74 | ------------------- 75 | ------------------- 76 | ------------------- 77 | 78 | 79 | --------------------------------------------------------------------------------