From f79a171c28cfa79912eadf2d7812c6c45e0b905c Mon Sep 17 00:00:00 2001 From: Robert Owen Date: Wed, 24 Feb 2021 14:13:28 +0100 Subject: [PATCH 1/2] Crash when creating cell extending JTACMonthCell programatically #1158 Changed access modifier to open to allow subclasses to access and create the required view --- Sources/JTAppleCalendar/JTACMonthCell.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/JTAppleCalendar/JTACMonthCell.swift b/Sources/JTAppleCalendar/JTACMonthCell.swift index cd0a2daf..c4d057d2 100644 --- a/Sources/JTAppleCalendar/JTACMonthCell.swift +++ b/Sources/JTAppleCalendar/JTACMonthCell.swift @@ -34,8 +34,8 @@ public protocol JTACCellMonthViewDelegate: AnyObject { } open class JTACMonthCell: UICollectionViewCell { - @IBOutlet var monthView: JTACCellMonthView? - weak var delegate: JTACCellMonthViewDelegate? + @IBOutlet open var monthView: JTACCellMonthView? + weak open var delegate: JTACCellMonthViewDelegate? func setupWith(configurationParameters: ConfigurationParameters, month: Month, From f12b84caa6a8418cced0c69e69cda3622c350bda Mon Sep 17 00:00:00 2001 From: Robert Owen Date: Fri, 26 Feb 2021 11:51:29 +0100 Subject: [PATCH 2/2] Extending functionality for JTACYearView and Delegates #1310 Added support for scrolling year view to a specified date and a new delegate method to allow for detection of user selection of a given month view. Changed visibility of the extension to provide default protocol implementations so apps using library will benefit. Extended sample app to show new functionality in year view --- .../TestYearViewViewController.swift | 16 ++ SampleJTAppleCalendar/Main.storyboard | 161 ++++++++++-------- .../JTACCollectionYearViewDelegates.swift | 18 ++ Sources/JTAppleCalendar/JTACYearView.swift | 33 ++++ .../JTACYearViewProtocols.swift | 8 +- 5 files changed, 167 insertions(+), 69 deletions(-) diff --git a/SampleJTAppleCalendar/Example Calendars/TestYearViewViewController.swift b/SampleJTAppleCalendar/Example Calendars/TestYearViewViewController.swift index af4d79f0..e6a89393 100644 --- a/SampleJTAppleCalendar/Example Calendars/TestYearViewViewController.swift +++ b/SampleJTAppleCalendar/Example Calendars/TestYearViewViewController.swift @@ -10,13 +10,21 @@ import JTAppleCalendar class TestYearViewViewController: UIViewController { @IBOutlet var calendarView: JTACYearView! + @IBOutlet var scrollToTodayButton: UIButton! + @IBOutlet var monthSelectLabel: UILabel! let f = DateFormatter() override func viewDidLoad() { calendarView.calendarDataSource = self calendarView.calendarDelegate = self super.viewDidLoad() + self.monthSelectLabel.text = "Click to select month" } + + @IBAction func scrollToToday(_ sender: UIButton) { + calendarView.scrollToDate(Date(), at: .top , animated: true) + } + } @@ -95,6 +103,14 @@ extension TestYearViewViewController: JTACYearViewDelegate, JTACYearViewDataSour return CGSize(width: width, height: height) } } + + func calendar(_ calendar: JTACYearView, didSelectMonth month: Month, dateRange: (start: Date, end: Date), cell: JTACMonthCell?, indexPath: IndexPath) { + let formatter1 = DateFormatter() + formatter1.dateFormat = "MMM YYYY" + let formatter2 = DateFormatter() + formatter2.dateFormat = "dd-MMM-YYYY" + self.monthSelectLabel.text = "Selected Month \(formatter1.string(from: dateRange.start))\nWith Date Range:\n\(formatter2.string(from: dateRange.start)) to \(formatter2.string(from: dateRange.end))\nFor index Path: \(indexPath)" + } } diff --git a/SampleJTAppleCalendar/Main.storyboard b/SampleJTAppleCalendar/Main.storyboard index 2c0eb425..7d532dd4 100644 --- a/SampleJTAppleCalendar/Main.storyboard +++ b/SampleJTAppleCalendar/Main.storyboard @@ -1,12 +1,13 @@ - + - + + - + @@ -21,7 +22,7 @@ - - - - - - - - - - - - - - - - - - - - + + + + + + + + + @@ -919,35 +944,35 @@ - - - - - - - - - - - - - - -