Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Example/MJCalendar/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,10 @@ class ViewController: UIViewController, UITableViewDataSource, UITableViewDelega
func calendar(_ calendarView: MJCalendarView, didSelectDate date: Date) {
self.scrollTableViewToDate(date)
}

func calendar(_ calendarView: MJCalendarView, shouldSelectDate date: Date) -> Bool {
return date == (Date() as NSDate).atStartOfDay()
}

//MARK: Toolbar actions
@IBAction func didTapMonth(_ sender: AnyObject) {
Expand Down
6 changes: 3 additions & 3 deletions Example/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
PODS:
- HexColors (2.3.0)
- MJCalendar (0.3.0):
- MJCalendar (0.4.0):
- NSDate-Escort (~> 1.5)
- UIView+JMFrame
- NSDate-Escort (1.7.0)
Expand All @@ -16,10 +16,10 @@ EXTERNAL SOURCES:

SPEC CHECKSUMS:
HexColors: 6ad3947c3447a055a3aa8efa859def096351fe5f
MJCalendar: fded170474124dc14ae81868f7ffc69bc5438b6f
MJCalendar: a529b085b0b988ae7b493ce7c000946cc186bf0e
NSDate-Escort: 3469fefab423c094108c2e864416b61b6ac0edbc
UIView+JMFrame: a907974c9d34b1c300aef85ae2a1a5af746f2b8a

PODFILE CHECKSUM: 4a8b5d26398ddbd90a4263c73faf04b15b5e7d20

COCOAPODS: 1.1.1
COCOAPODS: 1.2.0
15 changes: 14 additions & 1 deletion Pod/Classes/MJCalendarView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,22 @@ import NSDate_Escort
import UIView_JMFrame

public protocol MJCalendarViewDelegate: NSObjectProtocol {
func calendar(_ calendarView: MJCalendarView, shouldSelectDate date: Date) -> Bool
func calendar(_ calendarView: MJCalendarView, didChangePeriod periodDate: Date, bySwipe: Bool)
func calendar(_ calendarView: MJCalendarView, didSelectDate date: Date)
func calendar(_ calendarView: MJCalendarView, backgroundForDate date: Date) -> UIColor?
func calendar(_ calendarView: MJCalendarView, textColorForDate date: Date) -> UIColor?
}

public extension MJCalendarViewDelegate {
func calendar(_ calendarView: MJCalendarView, shouldSelectDate date: Date) -> Bool {
return true
}
}

open class MJCalendarView: UIView, UIScrollViewDelegate, MJComponentDelegate {
open var configuration: MJConfiguration
var periods: [MJPeriodView]?
var periods: [MJPeriodView]?
var weekLabelsView: MJWeekLabelsView?
var periodsContainerView: UIScrollView?

Expand Down Expand Up @@ -213,6 +220,7 @@ open class MJCalendarView: UIView, UIScrollViewDelegate, MJComponentDelegate {
}

open func selectDate(_ date: Date) {

let validatedDate = dateInRange(date)
if !self.isDateAlreadyShown(validatedDate) {
let periodDate = self.startDate(validatedDate, withOtherMonth: false)
Expand Down Expand Up @@ -290,6 +298,11 @@ open class MJCalendarView: UIView, UIScrollViewDelegate, MJComponentDelegate {
}

func componentView(_ componentView: MJComponentView, didSelectDate date: Date) {

if let calendarDelegate = calendarDelegate, !calendarDelegate.calendar(self, shouldSelectDate: date) {
return
}

self.selectDate(date)
self.calendarDelegate?.calendar(self, didSelectDate: date)
}
Expand Down