From fa3582e5ddf56d8b589ee834cefaada188d13a09 Mon Sep 17 00:00:00 2001 From: Lyubomir Marinov Date: Fri, 2 Feb 2018 16:22:37 +0200 Subject: [PATCH 1/4] Show border instead of filled background --- Koyomi/KoyomiCell.swift | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Koyomi/KoyomiCell.swift b/Koyomi/KoyomiCell.swift index 9b77fde..952155d 100644 --- a/Koyomi/KoyomiCell.swift +++ b/Koyomi/KoyomiCell.swift @@ -83,7 +83,9 @@ final class KoyomiCell: UICollectionViewCell { func configureAppearanse(of style: CellStyle, withColor color: UIColor, backgroundColor: UIColor, isSelected: Bool) { switch style { case .standard: - self.backgroundColor = isSelected ? color : backgroundColor + self.backgroundColor = UIColor.clear + self.layer.borderWidth = isSelected ? 1.0 : 0.0 + self.layer.borderColor = isSelected ? color.cgColor : backgroundColor.cgColor circularView.isHidden = true lineView.isHidden = true From 5b078403351f04a64495ba409ee05969e26562ca Mon Sep 17 00:00:00 2001 From: Lyubomir Marinov Date: Sun, 4 Feb 2018 22:30:59 +0200 Subject: [PATCH 2/4] # Show the actual month of the selected date --- Koyomi/DateExtension.swift | 12 ++++++++++++ Koyomi/DateModel.swift | 12 +++++++++++- Koyomi/Koyomi.swift | 11 ++++++++++- 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/Koyomi/DateExtension.swift b/Koyomi/DateExtension.swift index c22e0ca..b7a5d3e 100644 --- a/Koyomi/DateExtension.swift +++ b/Koyomi/DateExtension.swift @@ -12,6 +12,8 @@ extension Date { func formated(withFormat format: String = "yyyy/MM/dd") -> Date? { let formatter: DateFormatter = .init() formatter.dateFormat = format + formatter.timeZone = TimeZone.current + formatter.locale = Locale.current let dateString = formatter.string(from: self) return formatter.date(from: dateString) } @@ -24,6 +26,16 @@ extension Date { return nil } + func monthDifference(fromDate date: Date) -> Int { + + let currentCalendar = Calendar.current + + guard let startMonth = currentCalendar.ordinality(of: .month, in: .era, for: date) else { return 0 } + guard let endMonth = currentCalendar.ordinality(of: .month, in: .era, for: self) else { return 0 } + + return endMonth - startMonth + } + private func dateFromComponents(_ date: Date) -> Date? { let calender = Calendar.current let components = calender.dateComponents([.year, .month, .day], from: date) diff --git a/Koyomi/DateModel.swift b/Koyomi/DateModel.swift index 4448c80..af68a87 100644 --- a/Koyomi/DateModel.swift +++ b/Koyomi/DateModel.swift @@ -8,7 +8,16 @@ import UIKit -public enum MonthType { case previous, current, next } +public enum MonthType: Equatable { case previous, current, next, specific(diff: Int) } +public func ==(lhs: MonthType, rhs: MonthType) -> Bool { + switch (lhs, rhs) { + case (.previous, .previous): return true + case (.next, .next): return true + case (.current, .current): return true + case (.specific(let leftFrom), .specific(let rightFrom)): return leftFrom == rightFrom + default: return false + } +} final class DateModel: NSObject { @@ -347,6 +356,7 @@ private extension DateModel { case .previous: return -1 case .current: return 0 case .next: return 1 + case .specific(let diff): return diff } }() return calendar.date(byAdding: components, to: currentDate) ?? Date() diff --git a/Koyomi/Koyomi.swift b/Koyomi/Koyomi.swift index bfc7591..7cd0583 100644 --- a/Koyomi/Koyomi.swift +++ b/Koyomi/Koyomi.swift @@ -339,7 +339,16 @@ final public class Koyomi: UICollectionView { @discardableResult public func select(date: Date, to toDate: Date? = nil) -> Self { - model.select(from: date, to: toDate) + // Format `now` and `from` date + let now = Date().formated() ?? Date() + let fromDate = date.formated() ?? date + + // Calculate the month difference between `now` and `from` and display the month of the selected date + let difference = fromDate.monthDifference(fromDate: now) + display(in: .specific(diff: difference)) + + model.select(from: fromDate, to: toDate) + return self } From f17d2a3870973935ed40c5164c0ca2ea1aa699d7 Mon Sep 17 00:00:00 2001 From: Lyubomir Marinov Date: Sun, 4 Feb 2018 22:39:39 +0200 Subject: [PATCH 3/4] Update version --- Koyomi.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Koyomi.podspec b/Koyomi.podspec index f8e33fa..c3f0bf9 100644 --- a/Koyomi.podspec +++ b/Koyomi.podspec @@ -8,7 +8,7 @@ Pod::Spec.new do |s| s.name = 'Koyomi' - s.version = '1.2.7' + s.version = '1.2.8' s.summary = 'Simple customizable calendar component in Swift' s.description = <<-DESC From b85679751589e3059ed2a163d6169632dacdebea Mon Sep 17 00:00:00 2001 From: whoislyuboanyway <34651722+whoislyuboanyway@users.noreply.github.com> Date: Sun, 4 Feb 2018 22:47:01 +0200 Subject: [PATCH 4/4] Update README.md --- README.md | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 7eef133..f122083 100644 --- a/README.md +++ b/README.md @@ -70,10 +70,13 @@ Set custom class of `UICollectionView ` to `Koyomi` If you want to change displayed month, call `display(in: MonthType)`. `MonthType` is defined by three types. ```swift - public enum MonthType { case previous, current, next } + public enum MonthType { case previous, current, next, specific(diff: Int) } // change month koyomi.display(in: .next) + + // go back 4 months + koyomi.display(in: .specific(diff: -4)) ``` ### Hide days of other months @@ -173,6 +176,13 @@ You can select specific date . // If want to select multiple day. let dates: [Date] = [date1, date2, date3] koyomi.select(dates: dates) + + // ... or you can go around the world in 80 days and calculate when is your arrival date :) + let components = DateComponents.init(calendar: Calendar.current, day: +80) + + if let eightyDays = Calendar.current.date(byAdding: components, to: today) { + koyomi.select(date: eightyDays) // new feature: the calendar will actualy show that date as selected + } ``` You can also unselect available.