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
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ class CalendarDateRangePickerCell: UICollectionViewCell {
private let highlightedColor = UIColor(white: 0.9, alpha: 1.0)
private let disabledColor = UIColor.lightGray

var selectedColor: UIColor!
@objc var selectedColor: UIColor!

var date: Date?
var selectedView: UIView?
var halfBackgroundView: UIView?
var roundHighlightView: UIView?
@objc var date: Date?
@objc var selectedView: UIView?
@objc var halfBackgroundView: UIView?
@objc var roundHighlightView: UIView?

var label: UILabel!
@objc var label: UILabel!

override init(frame: CGRect) {
super.init(frame: frame)
Expand All @@ -33,7 +33,7 @@ class CalendarDateRangePickerCell: UICollectionViewCell {
initLabel()
}

func initLabel() {
@objc func initLabel() {
label = UILabel(frame: frame)
label.center = CGPoint(x: frame.size.width / 2, y: frame.size.height / 2)
label.font = UIFont(name: "HelveticaNeue", size: 15.0)
Expand All @@ -42,7 +42,7 @@ class CalendarDateRangePickerCell: UICollectionViewCell {
self.addSubview(label)
}

func reset() {
@objc func reset() {
self.backgroundColor = UIColor.clear
label.textColor = defaultTextColor
label.backgroundColor = UIColor.clear
Expand All @@ -60,7 +60,7 @@ class CalendarDateRangePickerCell: UICollectionViewCell {
}
}

func select() {
@objc func select() {
let width = self.frame.size.width
let height = self.frame.size.height
selectedView = UIView(frame: CGRect(x: (width - height) / 2, y: 0, width: height, height: height))
Expand All @@ -72,7 +72,7 @@ class CalendarDateRangePickerCell: UICollectionViewCell {
label.textColor = UIColor.white
}

func highlightRight() {
@objc func highlightRight() {
// This is used instead of highlight() when we need to highlight cell with a rounded edge on the left
let width = self.frame.size.width
let height = self.frame.size.height
Expand All @@ -84,7 +84,7 @@ class CalendarDateRangePickerCell: UICollectionViewCell {
addRoundHighlightView()
}

func highlightLeft() {
@objc func highlightLeft() {
// This is used instead of highlight() when we need to highlight the cell with a rounded edge on the right
let width = self.frame.size.width
let height = self.frame.size.height
Expand All @@ -96,7 +96,7 @@ class CalendarDateRangePickerCell: UICollectionViewCell {
addRoundHighlightView()
}

func addRoundHighlightView() {
@objc func addRoundHighlightView() {
let width = self.frame.size.width
let height = self.frame.size.height
roundHighlightView = UIView(frame: CGRect(x: (width - height) / 2, y: 0, width: height, height: height))
Expand All @@ -106,11 +106,11 @@ class CalendarDateRangePickerCell: UICollectionViewCell {
self.sendSubview(toBack: roundHighlightView!)
}

func highlight() {
@objc func highlight() {
self.backgroundColor = highlightedColor
}

func disable() {
@objc func disable() {
label.textColor = disabledColor
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import UIKit

class CalendarDateRangePickerHeaderView: UICollectionReusableView {

var label: UILabel!
@objc var label: UILabel!

override init(frame: CGRect) {
super.init(frame: frame)
Expand All @@ -22,7 +22,7 @@ class CalendarDateRangePickerHeaderView: UICollectionReusableView {
initLabel()
}

func initLabel() {
@objc func initLabel() {
label = UILabel(frame: frame)
label.center = CGPoint(x: frame.size.width / 2, y: frame.size.height / 2)
label.font = UIFont(name: "HelveticaNeue-Light", size: 17.0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,31 @@

import UIKit

@objc
public protocol CalendarDateRangePickerViewControllerDelegate {
func didCancelPickingDateRange()
func didPickDateRange(startDate: Date!, endDate: Date!)
@objc func didCancelPickingDateRange()
@objc func didPickDateRange(startDate: Date!, endDate: Date!)
}

public class CalendarDateRangePickerViewController: UICollectionViewController {

let cellReuseIdentifier = "CalendarDateRangePickerCell"
let headerReuseIdentifier = "CalendarDateRangePickerHeaderView"
@objc let cellReuseIdentifier = "CalendarDateRangePickerCell"
@objc let headerReuseIdentifier = "CalendarDateRangePickerHeaderView"

public var delegate: CalendarDateRangePickerViewControllerDelegate!
@objc public var delegate: CalendarDateRangePickerViewControllerDelegate!

let itemsPerRow = 7
let itemHeight: CGFloat = 40
let collectionViewInsets = UIEdgeInsets(top: 0, left: 25, bottom: 0, right: 25)
@objc let itemsPerRow = 7
@objc let itemHeight: CGFloat = 40
@objc let collectionViewInsets = UIEdgeInsets(top: 0, left: 25, bottom: 0, right: 25)

public var minimumDate: Date!
public var maximumDate: Date!
@objc public var minimumDate: Date!
@objc public var maximumDate: Date!

public var selectedStartDate: Date?
public var selectedEndDate: Date?
@objc public var selectedStartDate: Date?
@objc public var selectedEndDate: Date?

public var selectedColor = UIColor(red: 66/255.0, green: 150/255.0, blue: 240/255.0, alpha: 1.0)
public var titleText = "Select Dates"
@objc public var selectedColor = UIColor(red: 66/255.0, green: 150/255.0, blue: 240/255.0, alpha: 1.0)
@objc public var titleText = "Select Dates"

override public func viewDidLoad() {
super.viewDidLoad()
Expand All @@ -58,11 +59,11 @@ public class CalendarDateRangePickerViewController: UICollectionViewController {
self.navigationItem.rightBarButtonItem?.isEnabled = selectedStartDate != nil && selectedEndDate != nil
}

func didTapCancel() {
@objc func didTapCancel() {
delegate.didCancelPickingDateRange()
}

func didTapDone() {
@objc func didTapDone() {
if selectedStartDate == nil || selectedEndDate == nil {
return
}
Expand Down Expand Up @@ -197,23 +198,23 @@ extension CalendarDateRangePickerViewController {

// Helper functions

func getFirstDate() -> Date {
@objc func getFirstDate() -> Date {
var components = Calendar.current.dateComponents([.month, .year], from: minimumDate)
components.day = 1
return Calendar.current.date(from: components)!
}

func getFirstDateForSection(section: Int) -> Date {
@objc func getFirstDateForSection(section: Int) -> Date {
return Calendar.current.date(byAdding: .month, value: section, to: getFirstDate())!
}

func getMonthLabel(date: Date) -> String {
@objc func getMonthLabel(date: Date) -> String {
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "MMMM yyyy"
return dateFormatter.string(from: date)
}

func getWeekdayLabel(weekday: Int) -> String {
@objc func getWeekdayLabel(weekday: Int) -> String {
var components = DateComponents()
components.calendar = Calendar.current
components.weekday = weekday
Expand All @@ -226,25 +227,25 @@ extension CalendarDateRangePickerViewController {
return dateFormatter.string(from: date!)
}

func getWeekday(date: Date) -> Int {
@objc func getWeekday(date: Date) -> Int {
return Calendar.current.dateComponents([.weekday], from: date).weekday!
}

func getNumberOfDaysInMonth(date: Date) -> Int {
@objc func getNumberOfDaysInMonth(date: Date) -> Int {
return Calendar.current.range(of: .day, in: .month, for: date)!.count
}

func getDate(dayOfMonth: Int, section: Int) -> Date {
@objc func getDate(dayOfMonth: Int, section: Int) -> Date {
var components = Calendar.current.dateComponents([.month, .year], from: getFirstDateForSection(section: section))
components.day = dayOfMonth
return Calendar.current.date(from: components)!
}

func areSameDay(dateA: Date, dateB: Date) -> Bool {
@objc func areSameDay(dateA: Date, dateB: Date) -> Bool {
return Calendar.current.compare(dateA, to: dateB, toGranularity: .day) == ComparisonResult.orderedSame
}

func isBefore(dateA: Date, dateB: Date) -> Bool {
@objc func isBefore(dateA: Date, dateB: Date) -> Bool {
return Calendar.current.compare(dateA, to: dateB, toGranularity: .day) == ComparisonResult.orderedAscending
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -517,8 +517,7 @@
MODULE_NAME = ExampleApp;
PRODUCT_BUNDLE_IDENTIFIER = "com.miraan.CalendarDateRangePickerViewController-Example";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 4.0;
};
name = Debug;
};
Expand All @@ -533,8 +532,7 @@
MODULE_NAME = ExampleApp;
PRODUCT_BUNDLE_IDENTIFIER = "com.miraan.CalendarDateRangePickerViewController-Example";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 4.0;
};
name = Release;
};
Expand All @@ -554,8 +552,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 4.0;
};
name = Debug;
};
Expand All @@ -571,8 +568,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 4.0;
};
name = Release;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ class ViewController: UIViewController {

extension ViewController : CalendarDateRangePickerViewControllerDelegate {

func didCancelPickingDateRange() {
@objc func didCancelPickingDateRange() {
self.navigationController?.dismiss(animated: true, completion: nil)
}

func didPickDateRange(startDate: Date!, endDate: Date!) {
@objc func didPickDateRange(startDate: Date!, endDate: Date!) {
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "EEEE, MMM d, yyyy"
label.text = dateFormatter.string(from: startDate) + " to " + dateFormatter.string(from: endDate)
Expand Down
Loading