diff --git a/Example/JZCalendarWeekViewExample.xcodeproj/project.pbxproj b/Example/JZCalendarWeekViewExample.xcodeproj/project.pbxproj index c35f3c7..5ac67f6 100644 --- a/Example/JZCalendarWeekViewExample.xcodeproj/project.pbxproj +++ b/Example/JZCalendarWeekViewExample.xcodeproj/project.pbxproj @@ -30,6 +30,7 @@ 8E7263DF2074B55300ECF7CD /* EventCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8E7263DC2074B55300ECF7CD /* EventCell.swift */; }; 8E7263E02074B55300ECF7CD /* EventCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 8E7263DD2074B55300ECF7CD /* EventCell.xib */; }; 8E7263E32074B73300ECF7CD /* DefaultWeekView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8E7263E22074B73300ECF7CD /* DefaultWeekView.swift */; }; + 8E99A0A4213523C400415071 /* CurrentTimelineAll.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8E99A0A3213523C400415071 /* CurrentTimelineAll.swift */; }; 8E9A7DF520969919009AEB6E /* LongPressWeekView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8E9A7DF420969919009AEB6E /* LongPressWeekView.swift */; }; 8E9AE75B20773F3500B7004E /* ExampleOptionsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8E9AE75A20773F3500B7004E /* ExampleOptionsViewController.swift */; }; 8EBD62EA2096F8AD00520E58 /* LongPressViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8EBD62E92096F8AD00520E58 /* LongPressViewController.swift */; }; @@ -103,6 +104,7 @@ 8E7263DC2074B55300ECF7CD /* EventCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EventCell.swift; sourceTree = ""; }; 8E7263DD2074B55300ECF7CD /* EventCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = EventCell.xib; sourceTree = ""; }; 8E7263E22074B73300ECF7CD /* DefaultWeekView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DefaultWeekView.swift; sourceTree = ""; }; + 8E99A0A3213523C400415071 /* CurrentTimelineAll.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CurrentTimelineAll.swift; sourceTree = ""; }; 8E9A7DF420969919009AEB6E /* LongPressWeekView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LongPressWeekView.swift; sourceTree = ""; }; 8E9AE75A20773F3500B7004E /* ExampleOptionsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ExampleOptionsViewController.swift; sourceTree = ""; }; 8EBD62E92096F8AD00520E58 /* LongPressViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LongPressViewController.swift; sourceTree = ""; }; @@ -152,6 +154,7 @@ 8E54D53A208D6997007DD5FE /* CustomWeekView.swift */, 8E2E6566208D5F3600FB2CE4 /* BlackGridLine.swift */, 8E54D53C208D6A2B007DD5FE /* HourRowHeader.swift */, + 8E99A0A3213523C400415071 /* CurrentTimelineAll.swift */, ); path = CustomViews; sourceTree = ""; @@ -346,6 +349,7 @@ 8E5BB407207325AB00FA853F /* Extensions.swift in Sources */, 8E5BB3D42072F4A000FA853F /* DefaultViewController.swift in Sources */, 8E5BB4022073226100FA853F /* DefaultViewModel.swift in Sources */, + 8E99A0A4213523C400415071 /* CurrentTimelineAll.swift in Sources */, 8E2E6567208D5F3600FB2CE4 /* BlackGridLine.swift in Sources */, 8E5BB404207322BA00FA853F /* AllDayEvent.swift in Sources */, 8EBD62EA2096F8AD00520E58 /* LongPressViewController.swift in Sources */, diff --git a/Example/JZCalendarWeekViewExample/Source/Base.lproj/Main.storyboard b/Example/JZCalendarWeekViewExample/Source/Base.lproj/Main.storyboard index 64db344..7447c3c 100644 --- a/Example/JZCalendarWeekViewExample/Source/Base.lproj/Main.storyboard +++ b/Example/JZCalendarWeekViewExample/Source/Base.lproj/Main.storyboard @@ -1,5 +1,5 @@ - + @@ -119,7 +119,7 @@ - + diff --git a/Example/JZCalendarWeekViewExample/Source/CustomViews/CurrentTimelineAll.swift b/Example/JZCalendarWeekViewExample/Source/CustomViews/CurrentTimelineAll.swift new file mode 100644 index 0000000..5b4399a --- /dev/null +++ b/Example/JZCalendarWeekViewExample/Source/CustomViews/CurrentTimelineAll.swift @@ -0,0 +1,42 @@ +// +// CurrentTimelineAll.swift +// JZCalendarWeekViewExample +// +// Created by Jeff Zhang on 28/8/18. +// Copyright © 2018 Jeff Zhang. All rights reserved. +// + +import UIKit + +class CurrentTimelineAll: UICollectionReusableView { + + public var ballView = UIView() + public var lineView = UIView() + let ballSize: CGFloat = 6 + + public override init(frame: CGRect) { + super.init(frame: .zero) + + setupUI() + } + + open func setupUI() { + self.addSubviews([ballView, lineView]) + ballView.setAnchorCenterVerticallyTo(view: self, widthAnchor: ballSize, heightAnchor: ballSize, leadingAnchor: (leadingAnchor, 2)) + lineView.setAnchorCenterVerticallyTo(view: self, heightAnchor: 1, leadingAnchor: (leadingAnchor, 0), trailingAnchor: (trailingAnchor, 0)) + + ballView.backgroundColor = .purple + ballView.layer.cornerRadius = ballSize/2 + ballView.isHidden = true + lineView.backgroundColor = .purple + } + + open func updateView(needShowBallView: Bool) { + ballView.isHidden = !needShowBallView + } + + required public init?(coder aDecoder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + +} diff --git a/Example/JZCalendarWeekViewExample/Source/CustomViews/CustomWeekView.swift b/Example/JZCalendarWeekViewExample/Source/CustomViews/CustomWeekView.swift index 1350a59..f8fb81f 100644 --- a/Example/JZCalendarWeekViewExample/Source/CustomViews/CustomWeekView.swift +++ b/Example/JZCalendarWeekViewExample/Source/CustomViews/CustomWeekView.swift @@ -19,6 +19,7 @@ class CustomWeekView: JZBaseWeekView { self.flowLayout.register(BlackGridLine.self, forDecorationViewOfKind: JZDecorationViewKinds.verticalGridline) self.flowLayout.register(BlackGridLine.self, forDecorationViewOfKind: JZDecorationViewKinds.horizontalGridline) self.collectionView.register(HourRowHeader.self, forSupplementaryViewOfKind: JZSupplementaryViewKinds.rowHeader, withReuseIdentifier: HourRowHeader.className) + self.collectionView.register(CurrentTimelineAll.self, forSupplementaryViewOfKind: JZSupplementaryViewKinds.currentTimeline, withReuseIdentifier: CurrentTimelineAll.className) } override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { @@ -30,9 +31,16 @@ class CustomWeekView: JZBaseWeekView { override func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView { if kind == JZSupplementaryViewKinds.rowHeader { + let rowHeader = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: HourRowHeader.className, for: indexPath) as! HourRowHeader rowHeader.updateView(date: flowLayout.timeForRowHeader(at: indexPath)) return rowHeader + } else if kind == JZSupplementaryViewKinds.currentTimeline { + + let currentTimeline = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: CurrentTimelineAll.className, for: indexPath) as! CurrentTimelineAll + let isToday = Calendar.current.isDateInToday(flowLayout.dateForColumnHeader(at: indexPath)) + currentTimeline.updateView(needShowBallView: isToday) + return currentTimeline } return super.collectionView(collectionView, viewForSupplementaryElementOfKind: kind, at: indexPath) } diff --git a/Example/JZCalendarWeekViewExample/Source/ExampleOptionsViewController/ExampleOptionsViewController.swift b/Example/JZCalendarWeekViewExample/Source/ExampleOptionsViewController/ExampleOptionsViewController.swift index 8800409..778a5ec 100644 --- a/Example/JZCalendarWeekViewExample/Source/ExampleOptionsViewController/ExampleOptionsViewController.swift +++ b/Example/JZCalendarWeekViewExample/Source/ExampleOptionsViewController/ExampleOptionsViewController.swift @@ -137,7 +137,7 @@ extension ExampleOptionsViewController: UITableViewDelegate, UITableViewDataSour if section == 2 { if viewModel.optionsData[2].selectedIndex == 6 && viewModel.optionsData[3].subject != .firstDayOfWeek { - viewModel.insertDayOfWeekToData(firstDayOfWeek: .sunday) + viewModel.insertDayOfWeekToData(firstDayOfWeek: .Sunday) tableView.reloadData() } if viewModel.optionsData[2].selectedIndex != 6 && viewModel.optionsData[3].subject == .firstDayOfWeek { diff --git a/Example/JZCalendarWeekViewExample/Source/Utils/Extensions.swift b/Example/JZCalendarWeekViewExample/Source/Utils/Extensions.swift index cab2317..80d2fa5 100644 --- a/Example/JZCalendarWeekViewExample/Source/Utils/Extensions.swift +++ b/Example/JZCalendarWeekViewExample/Source/Utils/Extensions.swift @@ -61,18 +61,18 @@ extension JZHourGridDivision { extension DayOfWeek { var dayName: String { switch self { - case .sunday: return "Sunday" - case .monday: return "Monday" - case .tuesday: return "Tuesday" - case .wednesday: return "Wednesday" - case .thursday: return "Thursday" - case .friday: return "Friday" - case .saturday: return "Saturday" + case .Sunday: return "Sunday" + case .Monday: return "Monday" + case .Tuesday: return "Tuesday" + case .Wednesday: return "Wednesday" + case .Thursday: return "Thursday" + case .Friday: return "Friday" + case .Saturday: return "Saturday" } } static var dayOfWeekList: [DayOfWeek] { - return [.sunday, .monday, .tuesday, .wednesday, .thursday, .friday, .saturday] + return [.Sunday, .Monday, .Tuesday, .Wednesday, .Thursday, .Friday, .Saturday] } } diff --git a/Example/JZCalendarWeekViewExample/Supporting Files/Info.plist b/Example/JZCalendarWeekViewExample/Supporting Files/Info.plist index 334933f..f4fe553 100644 --- a/Example/JZCalendarWeekViewExample/Supporting Files/Info.plist +++ b/Example/JZCalendarWeekViewExample/Supporting Files/Info.plist @@ -15,9 +15,9 @@ CFBundlePackageType APPL CFBundleShortVersionString - 0.4.3 + 0.5.0 CFBundleVersion - 18061501 + 18082801 LSRequiresIPhoneOS UILaunchStoryboardName diff --git a/JZCalendarWeekView.podspec b/JZCalendarWeekView.podspec index 60d0644..ef59aa6 100644 --- a/JZCalendarWeekView.podspec +++ b/JZCalendarWeekView.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "JZCalendarWeekView" - s.version = "0.4.3" + s.version = "0.5.0" s.summary = "Calendar Week & Day View in iOS Swift" s.homepage = "https://github.com/zjfjack/JZCalendarWeekView" s.license = { :type => "MIT", :file => "LICENSE" } diff --git a/JZCalendarWeekView.xcodeproj/project.pbxproj b/JZCalendarWeekView.xcodeproj/project.pbxproj index 0d63873..1de8d3e 100644 --- a/JZCalendarWeekView.xcodeproj/project.pbxproj +++ b/JZCalendarWeekView.xcodeproj/project.pbxproj @@ -7,6 +7,7 @@ objects = { /* Begin PBXBuildFile section */ + 1FB6140D2130FE7400F08ACD /* JZCurrentTimelinePage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1FB6140C2130FE7400F08ACD /* JZCurrentTimelinePage.swift */; }; 8E023C78206C6E4B00C523BE /* JZWeekViewTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8E023C77206C6E4B00C523BE /* JZWeekViewTest.swift */; }; 8E023C7A206C6E4B00C523BE /* JZCalendarWeekView.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8E1BA94A206B4329007BE13C /* JZCalendarWeekView.framework */; }; 8E023C84206C732300C523BE /* JZBaseEvent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8E023C83206C732300C523BE /* JZBaseEvent.swift */; }; @@ -18,7 +19,7 @@ 8E1BA962206B4B99007BE13C /* JZRowHeader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8E1BA961206B4B99007BE13C /* JZRowHeader.swift */; }; 8E1BA964206B4E82007BE13C /* JZCornerHeader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8E1BA963206B4E82007BE13C /* JZCornerHeader.swift */; }; 8E1BA966206B4F0B007BE13C /* JZGridLine.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8E1BA965206B4F0B007BE13C /* JZGridLine.swift */; }; - 8E1BA968206B4F40007BE13C /* JZCurrentTimeIndicator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8E1BA967206B4F40007BE13C /* JZCurrentTimeIndicator.swift */; }; + 8E1BA968206B4F40007BE13C /* JZCurrentTimelineSection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8E1BA967206B4F40007BE13C /* JZCurrentTimelineSection.swift */; }; 8E1BA96A206B5350007BE13C /* JZWeekViewHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8E1BA969206B5350007BE13C /* JZWeekViewHelper.swift */; }; 8E1BA96C206B5B3F007BE13C /* JZColumnHeaderBackground.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8E1BA96B206B5B3F007BE13C /* JZColumnHeaderBackground.swift */; }; 8E1BA96E206B5B55007BE13C /* JZRowHeaderBackground.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8E1BA96D206B5B55007BE13C /* JZRowHeaderBackground.swift */; }; @@ -27,6 +28,7 @@ 8E40B2E020B65C4600FFEB68 /* JZAllDayEvent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8E40B2DF20B65C4600FFEB68 /* JZAllDayEvent.swift */; }; 8E478FA320846A8000668F05 /* Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8E478FA220846A8000668F05 /* Extensions.swift */; }; 8E5BB3FB2073154F00FA853F /* WeekViewHelperTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8E5BB3FA2073154F00FA853F /* WeekViewHelperTest.swift */; }; + 8E99A0A22134E84800415071 /* JZCollectionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8E99A0A12134E84800415071 /* JZCollectionView.swift */; }; 8EF7EBCD20A55C8E00D5CEEA /* JZAllDayCorner.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8EF7EBCC20A55C8E00D5CEEA /* JZAllDayCorner.swift */; }; 8EF7EBCF20A55CF900D5CEEA /* JZAllDayHeader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8EF7EBCE20A55CF900D5CEEA /* JZAllDayHeader.swift */; }; 8EF7EBD120A55D1000D5CEEA /* JZAllDayHeaderBackground.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8EF7EBD020A55D1000D5CEEA /* JZAllDayHeaderBackground.swift */; }; @@ -43,6 +45,7 @@ /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ + 1FB6140C2130FE7400F08ACD /* JZCurrentTimelinePage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JZCurrentTimelinePage.swift; sourceTree = ""; }; 8E023C75206C6E4B00C523BE /* JZCalendarWeekViewTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = JZCalendarWeekViewTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 8E023C77206C6E4B00C523BE /* JZWeekViewTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JZWeekViewTest.swift; sourceTree = ""; }; 8E023C79206C6E4B00C523BE /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; @@ -57,7 +60,7 @@ 8E1BA961206B4B99007BE13C /* JZRowHeader.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JZRowHeader.swift; sourceTree = ""; }; 8E1BA963206B4E82007BE13C /* JZCornerHeader.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JZCornerHeader.swift; sourceTree = ""; }; 8E1BA965206B4F0B007BE13C /* JZGridLine.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JZGridLine.swift; sourceTree = ""; }; - 8E1BA967206B4F40007BE13C /* JZCurrentTimeIndicator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JZCurrentTimeIndicator.swift; sourceTree = ""; }; + 8E1BA967206B4F40007BE13C /* JZCurrentTimelineSection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JZCurrentTimelineSection.swift; sourceTree = ""; }; 8E1BA969206B5350007BE13C /* JZWeekViewHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JZWeekViewHelper.swift; sourceTree = ""; }; 8E1BA96B206B5B3F007BE13C /* JZColumnHeaderBackground.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JZColumnHeaderBackground.swift; sourceTree = ""; }; 8E1BA96D206B5B55007BE13C /* JZRowHeaderBackground.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JZRowHeaderBackground.swift; sourceTree = ""; }; @@ -66,6 +69,7 @@ 8E40B2DF20B65C4600FFEB68 /* JZAllDayEvent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JZAllDayEvent.swift; sourceTree = ""; }; 8E478FA220846A8000668F05 /* Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Extensions.swift; sourceTree = ""; }; 8E5BB3FA2073154F00FA853F /* WeekViewHelperTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WeekViewHelperTest.swift; sourceTree = ""; }; + 8E99A0A12134E84800415071 /* JZCollectionView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JZCollectionView.swift; sourceTree = ""; }; 8EF7EBCC20A55C8E00D5CEEA /* JZAllDayCorner.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JZAllDayCorner.swift; sourceTree = ""; }; 8EF7EBCE20A55CF900D5CEEA /* JZAllDayHeader.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JZAllDayHeader.swift; sourceTree = ""; }; 8EF7EBD020A55D1000D5CEEA /* JZAllDayHeaderBackground.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JZAllDayHeaderBackground.swift; sourceTree = ""; }; @@ -122,6 +126,7 @@ isa = PBXGroup; children = ( 8E1BA95A206B4826007BE13C /* JZWeekViewFlowLayout.swift */, + 8E99A0A12134E84800415071 /* JZCollectionView.swift */, 8E1BA956206B47DA007BE13C /* JZBaseWeekView.swift */, 8E21E8AF20916A96002D72D0 /* JZLongPressWeekView.swift */, 8E1BA971206B61B7007BE13C /* JZLongPressEventCell.swift */, @@ -152,7 +157,8 @@ 8E1BA961206B4B99007BE13C /* JZRowHeader.swift */, 8E1BA963206B4E82007BE13C /* JZCornerHeader.swift */, 8E1BA965206B4F0B007BE13C /* JZGridLine.swift */, - 8E1BA967206B4F40007BE13C /* JZCurrentTimeIndicator.swift */, + 1FB6140C2130FE7400F08ACD /* JZCurrentTimelinePage.swift */, + 8E1BA967206B4F40007BE13C /* JZCurrentTimelineSection.swift */, 8E1BA96B206B5B3F007BE13C /* JZColumnHeaderBackground.swift */, 8E1BA96D206B5B55007BE13C /* JZRowHeaderBackground.swift */, 8EF7EBCC20A55C8E00D5CEEA /* JZAllDayCorner.swift */, @@ -282,12 +288,14 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 8E99A0A22134E84800415071 /* JZCollectionView.swift in Sources */, 8E1BA96C206B5B3F007BE13C /* JZColumnHeaderBackground.swift in Sources */, 8E478FA320846A8000668F05 /* Extensions.swift in Sources */, + 1FB6140D2130FE7400F08ACD /* JZCurrentTimelinePage.swift in Sources */, 8EF7EBCF20A55CF900D5CEEA /* JZAllDayHeader.swift in Sources */, 8E1BA95B206B4826007BE13C /* JZWeekViewFlowLayout.swift in Sources */, 8E40B2E020B65C4600FFEB68 /* JZAllDayEvent.swift in Sources */, - 8E1BA968206B4F40007BE13C /* JZCurrentTimeIndicator.swift in Sources */, + 8E1BA968206B4F40007BE13C /* JZCurrentTimelineSection.swift in Sources */, 8E1BA960206B4B84007BE13C /* JZColumnHeader.swift in Sources */, 8E023C84206C732300C523BE /* JZBaseEvent.swift in Sources */, 8E1BA964206B4E82007BE13C /* JZCornerHeader.swift in Sources */, diff --git a/JZCalendarWeekView/JZBaseWeekView.swift b/JZCalendarWeekView/JZBaseWeekView.swift index bc6ba64..aff4179 100644 --- a/JZCalendarWeekView/JZBaseWeekView.swift +++ b/JZCalendarWeekView/JZBaseWeekView.swift @@ -23,7 +23,7 @@ extension JZBaseViewDelegate { open class JZBaseWeekView: UIView { - public var collectionView: UICollectionView! + public var collectionView: JZCollectionView! public var flowLayout: JZWeekViewFlowLayout! /// The initial date of current collectionView. When page is not scrolling, the inital date is always @@ -36,6 +36,12 @@ open class JZBaseWeekView: UIView { } public var numOfDays: Int! public var scrollType: JZScrollType! + public var currentTimelineType: JZCurrentTimelineType! { + didSet { + let viewClass = currentTimelineType == .section ? JZCurrentTimelineSection.self : JZCurrentTimelinePage.self + self.collectionView.register(viewClass, forSupplementaryViewOfKind: JZSupplementaryViewKinds.currentTimeline, withReuseIdentifier: JZSupplementaryViewKinds.currentTimeline) + } + } public var firstDayOfWeek: DayOfWeek? public var allEventsBySection: [Date: [JZBaseEvent]]! { didSet { @@ -56,7 +62,6 @@ open class JZBaseWeekView: UIView { internal var isAllDaySupported: Bool! internal var initialContentOffset = CGPoint.zero internal var scrollSections:CGFloat! - private var isDirectionLocked = false override public init(frame: CGRect) { @@ -74,7 +79,7 @@ open class JZBaseWeekView: UIView { flowLayout = JZWeekViewFlowLayout() flowLayout.delegate = self - collectionView = UICollectionView(frame: bounds, collectionViewLayout: flowLayout) + collectionView = JZCollectionView(frame: bounds, collectionViewLayout: flowLayout) collectionView.delegate = self collectionView.dataSource = self collectionView.isDirectionalLockEnabled = true @@ -90,12 +95,11 @@ open class JZBaseWeekView: UIView { /// Override this function to customise items, supplimentaryViews and decorationViews open func registerViewClasses() { + // supplementary + self.collectionView.registerSupplimentaryViews([JZColumnHeader.self, JZCornerHeader.self, JZRowHeader.self, JZAllDayHeader.self]) - //supplementary - collectionView.registerSupplimentaryViews([JZColumnHeader.self, JZCornerHeader.self, JZRowHeader.self, JZAllDayHeader.self]) - - //decoration - flowLayout.registerDecorationViews([JZColumnHeaderBackground.self, JZRowHeaderBackground.self, JZCurrentTimeIndicator.self, + // decoration + flowLayout.registerDecorationViews([JZColumnHeaderBackground.self, JZRowHeaderBackground.self, JZAllDayHeaderBackground.self, JZAllDayCorner.self]) flowLayout.register(JZGridLine.self, forDecorationViewOfKind: JZDecorationViewKinds.verticalGridline) flowLayout.register(JZGridLine.self, forDecorationViewOfKind: JZDecorationViewKinds.horizontalGridline) @@ -117,21 +121,24 @@ open class JZBaseWeekView: UIView { - allEvents: The dictionary of all the events for present. JZWeekViewHelper.getIntraEventsByDate can help transform the data - firstDayOfWeek: First day of a week, **only works when numOfDays is 7**. Default value is Sunday - scrollType: The horizontal scroll type for this view. Default value is pageScroll + - currentTimelineType: The current time line type for this view. Default value is section */ - open func setupCalendar(numOfDays:Int, - setDate:Date, + open func setupCalendar(numOfDays: Int, + setDate: Date, allEvents: [Date:[JZBaseEvent]], scrollType: JZScrollType = .pageScroll, - firstDayOfWeek:DayOfWeek? = nil) { + firstDayOfWeek :DayOfWeek? = nil, + currentTimelineType: JZCurrentTimelineType = .section) { self.numOfDays = numOfDays if numOfDays == 7 { - updateFirstDayOfWeek(setDate: setDate, firstDayOfWeek: firstDayOfWeek ?? .sunday) + updateFirstDayOfWeek(setDate: setDate, firstDayOfWeek: firstDayOfWeek ?? .Sunday) } else { self.initDate = setDate.startOfDay.add(component: .day, value: -numOfDays) } self.allEventsBySection = allEvents self.scrollType = scrollType + self.currentTimelineType = currentTimelineType DispatchQueue.main.async { [unowned self] in self.layoutSubviews() @@ -326,7 +333,7 @@ open class JZBaseWeekView: UIView { } -extension JZBaseWeekView: UICollectionViewDelegate, UICollectionViewDataSource { +extension JZBaseWeekView: UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout { // In order to keep efficiency, only 3 pages exist at the same time, previous-current-next open func numberOfSections(in collectionView: UICollectionView) -> Int { @@ -347,7 +354,6 @@ extension JZBaseWeekView: UICollectionViewDelegate, UICollectionViewDataSource { preconditionFailure("This method must be overridden") } - open func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView { let view: UICollectionReusableView @@ -372,6 +378,14 @@ extension JZBaseWeekView: UICollectionViewDelegate, UICollectionViewDataSource { alldayHeader.updateView(views: []) view = alldayHeader + case JZSupplementaryViewKinds.currentTimeline: + if currentTimelineType == .page { + let currentTimeline = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: kind, for: indexPath) as! JZCurrentTimelinePage + view = getPageTypeCurrentTimeline(timeline: currentTimeline, indexPath: indexPath) + } else { + let currentTimeline = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: kind, for: indexPath) as! JZCurrentTimelineSection + view = getSectionTypeCurrentTimeline(timeline: currentTimeline, indexPath: indexPath) + } default: view = UICollectionReusableView() } @@ -423,7 +437,6 @@ extension JZBaseWeekView: UICollectionViewDelegate, UICollectionViewDataSource { } } - open func scrollViewDidScroll(_ scrollView: UIScrollView) { var lockedDirection: ScrollDirection! @@ -494,12 +507,29 @@ extension JZBaseWeekView: UICollectionViewDelegate, UICollectionViewDataSource { } } - ///Can be overrided to do some operations before reload + /// Can be overrided to do some operations before reload open func loadNextOrPrevPage(isNext: Bool) { let addValue = isNext ? numOfDays : -numOfDays self.initDate = self.initDate.add(component: .day, value: addValue!) self.forceReload() } + + /// Get the section Type current timeline + open func getSectionTypeCurrentTimeline(timeline: JZCurrentTimelineSection, indexPath: IndexPath) -> UICollectionReusableView { + let date = flowLayout.dateForColumnHeader(at: indexPath) + timeline.isHidden = !date.isToday + return timeline + } + + /// Get the page Type current timeline + /// Rules are quite confused for now + open func getPageTypeCurrentTimeline(timeline: JZCurrentTimelinePage, indexPath: IndexPath) -> UICollectionReusableView { + let date = flowLayout.dateForColumnHeader(at: indexPath) + let daysToToday = Date.daysBetween(start: date, end: Date(), ignoreHours: true) + timeline.isHidden = abs(daysToToday) > numOfDays - 1 + timeline.updateView(needShowBallView: daysToToday == 0) + return timeline + } } extension JZBaseWeekView: WeekViewFlowLayoutDelegate { diff --git a/JZCalendarWeekView/JZCollectionView.swift b/JZCalendarWeekView/JZCollectionView.swift new file mode 100644 index 0000000..81ac931 --- /dev/null +++ b/JZCalendarWeekView/JZCollectionView.swift @@ -0,0 +1,42 @@ +// +// JZCollectionView.swift +// JZCalendarWeekView +// +// Created by Jeff Zhang on 28/8/18. +// Copyright © 2018 Jeff Zhang. All rights reserved. +// + +import UIKit + +public class JZCollectionView: UICollectionView { + + public var registeredCells = [String]() // [identifiers] + public var registeredSupplementaryClasses = Dictionary() // [kind:identifiers] + + public override func register(_ nib: UINib?, forCellWithReuseIdentifier identifier: String) { + super.register(nib, forCellWithReuseIdentifier: identifier) + registeredCells.append(identifier) + } + + public override func register(_ cellClass: AnyClass?, forCellWithReuseIdentifier identifier: String) { + super.register(cellClass, forCellWithReuseIdentifier: identifier) + registeredCells.append(identifier) + } + + public override func register(_ nib: UINib?, forSupplementaryViewOfKind kind: String, withReuseIdentifier identifier: String) { + super.register(nib, forSupplementaryViewOfKind: kind, withReuseIdentifier: identifier) + registeredSupplementaryClasses[kind] = identifier + } + + public override func register(_ viewClass: AnyClass?, forSupplementaryViewOfKind elementKind: String, withReuseIdentifier identifier: String) { + super.register(viewClass, forSupplementaryViewOfKind: elementKind, withReuseIdentifier: identifier) + registeredSupplementaryClasses[elementKind] = identifier + } + + public func registerSupplimentaryViews(_ viewClasses: [UICollectionReusableView.Type]) { + viewClasses.forEach { + self.register($0, forSupplementaryViewOfKind: $0.className, withReuseIdentifier: $0.className) + } + } + +} diff --git a/JZCalendarWeekView/JZWeekViewFlowLayout.swift b/JZCalendarWeekView/JZWeekViewFlowLayout.swift index 6917717..9bb13e8 100644 --- a/JZCalendarWeekView/JZWeekViewFlowLayout.swift +++ b/JZCalendarWeekView/JZWeekViewFlowLayout.swift @@ -14,7 +14,7 @@ public protocol WeekViewFlowLayoutDelegate: class { /// Get the end time for given item indexPath func collectionView(_ collectionView: UICollectionView, layout: JZWeekViewFlowLayout, endTimeForItemAtIndexPath indexPath: IndexPath) -> Date /// TODO: Get the cell type for given item indexPath (Used for different cell types in the future) - func collectionView(_ collectionView: UICollectionView, layout: JZWeekViewFlowLayout, cellTypeForItemAtIndexPath indexPath: IndexPath) -> String + func collectionView(_ collectionView: UICollectionView, layout: JZWeekViewFlowLayout, cellTypeForItemAtIndexPath indexPath: IndexPath) -> String } open class JZWeekViewFlowLayout: UICollectionViewFlowLayout { @@ -141,6 +141,12 @@ open class JZWeekViewFlowLayout: UICollectionViewFlowLayout { collectionView!.reloadData() } + public func registerDecorationViews(_ viewClasses: [UICollectionReusableView.Type]) { + viewClasses.forEach { + self.register($0, forDecorationViewOfKind: $0.className) + } + } + override open func register(_ viewClass: AnyClass?, forDecorationViewOfKind elementKind: String) { super.register(viewClass, forDecorationViewOfKind: elementKind) registeredDecorationClasses[elementKind] = viewClass @@ -184,31 +190,21 @@ open class JZWeekViewFlowLayout: UICollectionViewFlowLayout { let calendarContentMinY = columnHeaderHeight + contentsMargin.top + allDayHeaderHeight // Current time line - var hasTimeLineInAllSections = false + // TODO: Should improve this method, otherwise every column will display a timeline view sectionIndexes.enumerate(_:) { (section, stop) in - let indexPath = IndexPath(row: 0, section: section) - // Only show current time line in today section - if dateForColumnHeader(at: indexPath).isToday { - let timeY = calendarContentMinY + nearbyint(CGFloat(currentTimeComponents.hour!) * hourHeight - + CGFloat(currentTimeComponents.minute!) * minuteHeight) - let sectionMinX = calendarContentMinX + sectionWidth * CGFloat(section) - let currentTimeHorizontalGridlineMinY = timeY - nearbyint(defaultGridThickness / 2.0) - defaultCurrentTimeLineHeight/2 - (attributes, currentTimeLineAttributes) = layoutAttributesForDecorationView(at: IndexPath(item: 0, section: section), - ofKind: JZDecorationViewKinds.currentTimeGridline, - withItemCache: currentTimeLineAttributes) - attributes.frame = CGRect(x: sectionMinX, y: currentTimeHorizontalGridlineMinY, width: sectionWidth, height: defaultCurrentTimeLineHeight) - attributes.zIndex = zIndexForElementKind(JZDecorationViewKinds.currentTimeGridline) - //Remove some reused sections attributes - currentTimeLineAttributes.removeAll() - currentTimeLineAttributes[indexPath] = attributes - hasTimeLineInAllSections = true - } + let sectionMinX = calendarContentMinX + sectionWidth * CGFloat(section) + let timeY = calendarContentMinY + nearbyint(CGFloat(currentTimeComponents.hour!) * hourHeight + + CGFloat(currentTimeComponents.minute!) * minuteHeight) + let currentTimeHorizontalGridlineMinY = timeY - nearbyint(defaultGridThickness / 2.0) - defaultCurrentTimeLineHeight/2 + (attributes, currentTimeLineAttributes) = layoutAttributesForSupplemantaryView(at: IndexPath(item: 0, section: section), + ofKind: JZSupplementaryViewKinds.currentTimeline, + withItemCache: currentTimeLineAttributes) + attributes.frame = CGRect(x: sectionMinX, y: currentTimeHorizontalGridlineMinY, width: sectionWidth, height: defaultCurrentTimeLineHeight) + attributes.zIndex = zIndexForElementKind(JZSupplementaryViewKinds.currentTimeline) } - if !hasTimeLineInAllSections {currentTimeLineAttributes.removeAll()} - // Corner Header - (attributes, cornerHeaderAttributes) = layoutAttributesForSupplemantaryView(at: IndexPath(row: 0, section: 0), + (attributes, cornerHeaderAttributes) = layoutAttributesForSupplemantaryView(at: IndexPath(item: 0, section: 0), ofKind: JZSupplementaryViewKinds.cornerHeader, withItemCache: cornerHeaderAttributes) attributes.frame = CGRect(origin: collectionView!.contentOffset, size: CGSize(width: rowHeaderWidth, height: columnHeaderHeight)) @@ -227,7 +223,7 @@ open class JZWeekViewFlowLayout: UICollectionViewFlowLayout { } // Row Header Background - (attributes, rowHeaderBackgroundAttributes) = layoutAttributesForDecorationView(at: IndexPath(row: 0, section: 0), + (attributes, rowHeaderBackgroundAttributes) = layoutAttributesForDecorationView(at: IndexPath(item: 0, section: 0), ofKind: JZDecorationViewKinds.rowHeaderBackground, withItemCache: rowHeaderBackgroundAttributes) attributes.frame = CGRect(x: rowHeaderMinX, y: collectionView!.contentOffset.y, width: rowHeaderWidth, height: collectionView!.frame.height) @@ -250,7 +246,7 @@ open class JZWeekViewFlowLayout: UICollectionViewFlowLayout { // All-Day header background (attributes, allDayHeaderBackgroundAttributes) = - layoutAttributesForDecorationView(at: IndexPath(row: 0, section: 0), + layoutAttributesForDecorationView(at: IndexPath(item: 0, section: 0), ofKind: JZDecorationViewKinds.allDayHeaderBackground, withItemCache: allDayHeaderBackgroundAttributes) attributes.frame = CGRect(origin: CGPoint(x:collectionView!.contentOffset.x,y: collectionView!.contentOffset.y + columnHeaderHeight) , @@ -259,7 +255,7 @@ open class JZWeekViewFlowLayout: UICollectionViewFlowLayout { attributes.zIndex = zIndexForElementKind(JZDecorationViewKinds.allDayHeaderBackground) (attributes, allDayCornerAttributes) = - layoutAttributesForDecorationView(at: IndexPath(row: 0, section: 0), + layoutAttributesForDecorationView(at: IndexPath(item: 0, section: 0), ofKind: JZDecorationViewKinds.allDayCorner, withItemCache: allDayCornerAttributes) attributes.frame = CGRect(origin: CGPoint(x:collectionView!.contentOffset.x,y: collectionView!.contentOffset.y + columnHeaderHeight), @@ -267,7 +263,7 @@ open class JZWeekViewFlowLayout: UICollectionViewFlowLayout { attributes.zIndex = zIndexForElementKind(JZDecorationViewKinds.allDayCorner) // column header background - (attributes, columnHeaderBackgroundAttributes) = layoutAttributesForDecorationView(at: IndexPath(row: 0, section: 0), + (attributes, columnHeaderBackgroundAttributes) = layoutAttributesForDecorationView(at: IndexPath(item: 0, section: 0), ofKind: JZDecorationViewKinds.columnHeaderBackground, withItemCache: columnHeaderBackgroundAttributes) let attributesHeight = columnHeaderHeight + (collectionView!.contentOffset.y < 0 ? abs(collectionView!.contentOffset.y) : 0 ) @@ -412,6 +408,8 @@ open class JZWeekViewFlowLayout: UICollectionViewFlowLayout { return cornerHeaderAttributes[indexPath] case JZSupplementaryViewKinds.allDayHeader: return allDayHeaderAttributes[indexPath] + case JZSupplementaryViewKinds.currentTimeline: + return currentTimeLineAttributes[indexPath] default: return nil } @@ -465,6 +463,13 @@ open class JZWeekViewFlowLayout: UICollectionViewFlowLayout { } } + func layoutAttributesForDecorationView(customAttributes: UICollectionViewLayoutAttributes, + withItemCache itemCache: AttDic) -> (UICollectionViewLayoutAttributes, AttDic) { + var _itemCache = itemCache + _itemCache[customAttributes.indexPath] = customAttributes + return (customAttributes, _itemCache) + } + private func layoutAttributesForSupplemantaryView(at indexPath: IndexPath, ofKind kind: String, withItemCache itemCache: AttDic) -> (UICollectionViewLayoutAttributes, AttDic) { @@ -578,6 +583,7 @@ open class JZWeekViewFlowLayout: UICollectionViewFlowLayout { cachedStartTimeDateComponents.removeAll() cachedEndTimeDateComponents.removeAll() + currentTimeLineAttributes.removeAll() verticalGridlineAttributes.removeAll() horizontalGridlineAttributes.removeAll() columnHeaderAttributes.removeAll() @@ -692,7 +698,7 @@ open class JZWeekViewFlowLayout: UICollectionViewFlowLayout { return minOverlayZ + 5 case JZDecorationViewKinds.columnHeaderBackground: return minOverlayZ + 4 - case JZDecorationViewKinds.currentTimeGridline: + case JZSupplementaryViewKinds.currentTimeline: return minOverlayZ + 3 case JZDecorationViewKinds.horizontalGridline: return minBackgroundZ + 2 diff --git a/JZCalendarWeekView/JZWeekViewHelper.swift b/JZCalendarWeekView/JZWeekViewHelper.swift index 80c2440..3be5904 100644 --- a/JZCalendarWeekView/JZWeekViewHelper.swift +++ b/JZCalendarWeekView/JZWeekViewHelper.swift @@ -12,6 +12,7 @@ public enum JZSupplementaryViewKinds { public static let cornerHeader = JZCornerHeader.className public static let allDayHeader = JZAllDayHeader.className public static let eventCell = "eventCell" + public static let currentTimeline = "currentTimeline" } public enum JZDecorationViewKinds { @@ -21,7 +22,6 @@ public enum JZDecorationViewKinds { public static let allDayCorner = JZAllDayCorner.className public static let verticalGridline = "VerticalGridline" public static let horizontalGridline = "HorizontalGridline" - public static let currentTimeGridline = JZCurrentTimeIndicator.className } enum ScrollDirection { @@ -45,7 +45,7 @@ public enum JZHourGridDivision: Int { } public enum DayOfWeek: Int { - case sunday = 1, monday, tuesday, wednesday, thursday, friday, saturday + case Sunday = 1, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday } public enum JZScrollType { @@ -54,6 +54,11 @@ public enum JZScrollType { //TODO: - infiniteScroll } +public enum JZCurrentTimelineType { + case section // Display the current time line only in today's section + case page // Display the current time line in the whole page including today +} + open class JZWeekViewHelper { /** diff --git a/JZCalendarWeekView/ReusableViews/JZCurrentTimelinePage.swift b/JZCalendarWeekView/ReusableViews/JZCurrentTimelinePage.swift new file mode 100644 index 0000000..4232730 --- /dev/null +++ b/JZCalendarWeekView/ReusableViews/JZCurrentTimelinePage.swift @@ -0,0 +1,42 @@ +// +// JZCurrentTimelinePage.swift +// JZCalendarWeekView +// +// Created by Jeff Zhang on 25/8/18. +// Copyright © 2018 Jeff Zhang. All rights reserved. +// + +import UIKit + +open class JZCurrentTimelinePage: UICollectionReusableView { + + public var ballView = UIView() + public var lineView = UIView() + let ballSize: CGFloat = 6 + + public override init(frame: CGRect) { + super.init(frame: .zero) + + setupUI() + } + + open func setupUI() { + self.addSubviews([ballView, lineView]) + ballView.setAnchorCenterVerticallyTo(view: self, widthAnchor: ballSize, heightAnchor: ballSize, leadingAnchor: (leadingAnchor, 2)) + lineView.setAnchorCenterVerticallyTo(view: self, heightAnchor: 1, leadingAnchor: (leadingAnchor, 0), trailingAnchor: (trailingAnchor, 0)) + + ballView.backgroundColor = JZWeekViewColors.appleCalendarRed + ballView.layer.cornerRadius = ballSize/2 + ballView.isHidden = true + lineView.backgroundColor = JZWeekViewColors.appleCalendarRed + } + + open func updateView(needShowBallView: Bool) { + ballView.isHidden = !needShowBallView + } + + required public init?(coder aDecoder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + +} diff --git a/JZCalendarWeekView/ReusableViews/JZCurrentTimeIndicator.swift b/JZCalendarWeekView/ReusableViews/JZCurrentTimelineSection.swift similarity index 89% rename from JZCalendarWeekView/ReusableViews/JZCurrentTimeIndicator.swift rename to JZCalendarWeekView/ReusableViews/JZCurrentTimelineSection.swift index d5116d2..9b32f1f 100644 --- a/JZCalendarWeekView/ReusableViews/JZCurrentTimeIndicator.swift +++ b/JZCalendarWeekView/ReusableViews/JZCurrentTimelineSection.swift @@ -1,5 +1,5 @@ // -// JZCurrentTimeIndicator.swift +// JZCurrentTimelineSection.swift // JZCalendarWeekView // // Created by Jeff Zhang on 28/3/18. @@ -8,7 +8,7 @@ import Foundation -open class JZCurrentTimeIndicator: UICollectionReusableView { +open class JZCurrentTimelineSection: UICollectionReusableView { public var halfBallView = UIView() public var lineView = UIView() @@ -20,7 +20,7 @@ open class JZCurrentTimeIndicator: UICollectionReusableView { setupUI() } - private func setupUI() { + open func setupUI() { self.addSubviews([halfBallView, lineView]) halfBallView.setAnchorCenterVerticallyTo(view: self, widthAnchor: halfBallSize, heightAnchor: halfBallSize, leadingAnchor: (leadingAnchor, -5)) lineView.setAnchorCenterVerticallyTo(view: self, heightAnchor: 1, leadingAnchor: (halfBallView.trailingAnchor, 0), trailingAnchor: (trailingAnchor, 0)) diff --git a/JZCalendarWeekView/Utils/Extensions.swift b/JZCalendarWeekView/Utils/Extensions.swift index 1dfdb6d..5bf5ba1 100644 --- a/JZCalendarWeekView/Utils/Extensions.swift +++ b/JZCalendarWeekView/Utils/Extensions.swift @@ -14,13 +14,7 @@ extension NSObject { } } - extension UICollectionView { - func registerSupplimentaryViews(_ viewClasses: [UICollectionReusableView.Type]) { - viewClasses.forEach { - self.register($0, forSupplementaryViewOfKind: $0.className, withReuseIdentifier: $0.className) - } - } func setContentOffsetWithoutDelegate(_ contentOffset: CGPoint, animated: Bool) { let tempDelegate = self.delegate @@ -30,14 +24,6 @@ extension UICollectionView { } } -extension UICollectionViewFlowLayout { - func registerDecorationViews(_ viewClasses: [UICollectionReusableView.Type]) { - viewClasses.forEach { - self.register($0, forDecorationViewOfKind: $0.className) - } - } -} - // Anchor Constraints from JZiOSFramework extension UIView { @@ -174,6 +160,16 @@ extension Date { return Calendar.current.isDateInTomorrow(self) } + static func getCurrentWeekDays(firstDayOfWeek: DayOfWeek?=nil) -> [Date] { + var calendar = Calendar.current + calendar.firstWeekday = (firstDayOfWeek ?? .Sunday).rawValue + let today = calendar.startOfDay(for: Date()) + let dayOfWeek = calendar.component(.weekday, from: today) + let weekdays = calendar.range(of: .weekday, in: .weekOfYear, for: today)! + let days = (weekdays.lowerBound ..< weekdays.upperBound).compactMap { calendar.date(byAdding: .day, value: $0 - dayOfWeek, to: today) } + return days + } + func add(component: Calendar.Component, value: Int) -> Date { return Calendar.current.date(byAdding: component, value: value, to: self)! } diff --git a/JZCalendarWeekView/Utils/JZWeekViewColors.swift b/JZCalendarWeekView/Utils/JZWeekViewColors.swift index 4a9106e..315c972 100644 --- a/JZCalendarWeekView/Utils/JZWeekViewColors.swift +++ b/JZCalendarWeekView/Utils/JZWeekViewColors.swift @@ -18,7 +18,7 @@ class JZWeekViewColors { class var gridLine: UIColor { return UIColor.lightGray } class var today: UIColor { return UIColor(hex: 0x0089FF) } - + class var appleCalendarRed: UIColor { return UIColor(hex: 0xFC3D39) } } diff --git a/README.md b/README.md index e81a1a6..a1c2840 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ Inspired from WRCalendarView (https://github.com/wayfinders/WRCalendarView) - [x] Two Types of Long Press Gestures: Add a new event & Move an existing event - [x] Events display on calendar view (supports events with conflict time and events crossing few days) - [x] Support all device orientations (including iPhone X Landscape) and iPad (Slide Over and Split View) -- [x] Current time line displays in today section only +- [x] Customise your own current timeline - [x] All-Day Events @@ -68,7 +68,7 @@ override func registerViewClasses() { collectionView.register(RowHeader.self, forSupplementaryViewOfKind: JZSupplementaryViewKinds.rowHeader, withReuseIdentifier: "RowHeader") } ``` -If you want to use your own supplementryView, you should register it and override the following function +If you want to use your own supplementryView (including your current timeline), you should register it and override the following function ```swift override func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView @@ -155,13 +155,12 @@ For futher usage, you can also check the example project, some comments in code JZCalendarWeekView can be added to your project by adding the following line to your `Podfile`: ```ruby -pod 'JZCalendarWeekView', '~> 0.4' +pod 'JZCalendarWeekView', '~> 0.5' ``` ## Todo - [ ] Limited date range: First Date and Last Date in CalendarView -- [ ] Apple type of Timeline (a whole page) & Timeline color change - [ ] DecorationView for different background views (refer to #12) - [ ] Theme implementation - [ ] New scroll type: Infinite scroll