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
2 changes: 1 addition & 1 deletion CalendarDateRangePickerViewController.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ This is a calendar date range picker view controller written in Swift for iOS. T
s.source = { :git => 'https://github.com/miraan/CalendarDateRangePickerViewController.git', :tag => s.version.to_s }
# s.social_media_url = 'https://twitter.com/<TWITTER_USERNAME>'

s.ios.deployment_target = '8.0'
s.ios.deployment_target = '12.0'

s.source_files = 'CalendarDateRangePickerViewController/Classes/**/*'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@
import UIKit

class CalendarDateRangePickerCell: UICollectionViewCell {

private let defaultTextColor = UIColor.darkGray
private let highlightedColor = UIColor(white: 0.9, alpha: 1.0)
private let defaultTextColor = UIColor(red: 56/255.0, green: 58/255.0, blue: 101/255.0, alpha: 1)
private let highlightedColor = UIColor(red: 233/255.0, green: 233/255.0, blue: 248/255.0, alpha: 1)
private let disabledColor = UIColor.lightGray

var selectedColor: UIColor!
Expand Down Expand Up @@ -67,7 +66,7 @@ class CalendarDateRangePickerCell: UICollectionViewCell {
selectedView?.backgroundColor = selectedColor
selectedView?.layer.cornerRadius = height / 2
self.addSubview(selectedView!)
self.sendSubview(toBack: selectedView!)
self.sendSubviewToBack(selectedView!)

label.textColor = UIColor.white
}
Expand All @@ -79,7 +78,7 @@ class CalendarDateRangePickerCell: UICollectionViewCell {
halfBackgroundView = UIView(frame: CGRect(x: width / 2, y: 0, width: width / 2, height: height))
halfBackgroundView?.backgroundColor = highlightedColor
self.addSubview(halfBackgroundView!)
self.sendSubview(toBack: halfBackgroundView!)
self.sendSubviewToBack(halfBackgroundView!)

addRoundHighlightView()
}
Expand All @@ -91,7 +90,7 @@ class CalendarDateRangePickerCell: UICollectionViewCell {
halfBackgroundView = UIView(frame: CGRect(x: 0, y: 0, width: width / 2, height: height))
halfBackgroundView?.backgroundColor = highlightedColor
self.addSubview(halfBackgroundView!)
self.sendSubview(toBack: halfBackgroundView!)
self.sendSubviewToBack(halfBackgroundView!)

addRoundHighlightView()
}
Expand All @@ -103,7 +102,7 @@ class CalendarDateRangePickerCell: UICollectionViewCell {
roundHighlightView?.backgroundColor = highlightedColor
roundHighlightView?.layer.cornerRadius = height / 2
self.addSubview(roundHighlightView!)
self.sendSubview(toBack: roundHighlightView!)
self.sendSubviewToBack(roundHighlightView!)
}

func highlight() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,20 @@ public class CalendarDateRangePickerViewController: UICollectionViewController {
public var selectedStartDate: Date?
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 selectedColor = UIColor(red: 56/255.0, green: 58/255.0, blue: 101/255.0, alpha: 1)
public var textFont = UIFont.systemFont(ofSize: 14)
public var weekLabelColor = UIColor(red: 56/255.0, green: 58/255.0, blue: 101/255.0, alpha: 1)

public var headerTextFont = UIFont.systemFont(ofSize: 14)
public var headerTextColor = UIColor.black

public var titleText = "Select Dates"

public var navTitleColor = UIColor.black
public var navTitleFont = UIFont.systemFont(ofSize: 15)

public var barbuttonColor = UIColor.blue
public var barbuttonFont = UIFont.systemFont(ofSize: 13)

override public func viewDidLoad() {
super.viewDidLoad()

Expand All @@ -41,9 +52,9 @@ public class CalendarDateRangePickerViewController: UICollectionViewController {
collectionView?.dataSource = self
collectionView?.delegate = self
collectionView?.backgroundColor = UIColor.white

collectionView?.register(CalendarDateRangePickerCell.self, forCellWithReuseIdentifier: cellReuseIdentifier)
collectionView?.register(CalendarDateRangePickerHeaderView.self, forSupplementaryViewOfKind: UICollectionElementKindSectionHeader, withReuseIdentifier: headerReuseIdentifier)
collectionView?.register(CalendarDateRangePickerHeaderView.self, forSupplementaryViewOfKind: UICollectionView.elementKindSectionHeader, withReuseIdentifier: headerReuseIdentifier)
collectionView?.contentInset = collectionViewInsets

if minimumDate == nil {
Expand All @@ -53,16 +64,24 @@ public class CalendarDateRangePickerViewController: UICollectionViewController {
maximumDate = Calendar.current.date(byAdding: .year, value: 3, to: minimumDate)
}

self.navigationController?.navigationBar.titleTextAttributes = [NSAttributedString.Key.foregroundColor: navTitleColor, NSAttributedString.Key.font: navTitleFont]

self.navigationItem.leftBarButtonItem = UIBarButtonItem(title: "Cancel", style: .plain, target: self, action: #selector(CalendarDateRangePickerViewController.didTapCancel))
self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Done", style: .done, target: self, action: #selector(CalendarDateRangePickerViewController.didTapDone))
self.navigationItem.rightBarButtonItem?.isEnabled = selectedStartDate != nil && selectedEndDate != nil
self.navigationItem.leftBarButtonItem?.setTitleTextAttributes([
NSAttributedString.Key.font: barbuttonFont,
NSAttributedString.Key.foregroundColor: barbuttonColor], for: [.normal, .selected, .disabled])
self.navigationItem.rightBarButtonItem?.setTitleTextAttributes([
NSAttributedString.Key.font: barbuttonFont,
NSAttributedString.Key.foregroundColor: barbuttonColor], for: [.normal, .selected, .disabled])
}

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

func didTapDone() {
@objc func didTapDone() {
if selectedStartDate == nil || selectedEndDate == nil {
return
}
Expand Down Expand Up @@ -91,10 +110,12 @@ extension CalendarDateRangePickerViewController {
override public func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: cellReuseIdentifier, for: indexPath) as! CalendarDateRangePickerCell
cell.selectedColor = self.selectedColor
cell.label.font = self.textFont
cell.reset()
let blankItems = getWeekday(date: getFirstDateForSection(section: indexPath.section)) - 1
if indexPath.item < 7 {
cell.label.text = getWeekdayLabel(weekday: indexPath.item + 1)
cell.label.textColor = self.weekLabelColor
} else if indexPath.item < 7 + blankItems {
cell.label.text = ""
} else {
Expand Down Expand Up @@ -132,9 +153,11 @@ extension CalendarDateRangePickerViewController {

override public func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
switch kind {
case UICollectionElementKindSectionHeader:
case UICollectionView.elementKindSectionHeader:
let headerView = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: headerReuseIdentifier, for: indexPath) as! CalendarDateRangePickerHeaderView
headerView.label.text = getMonthLabel(date: getFirstDateForSection(section: indexPath.section))
headerView.label.text = getMonthLabel(date: getFirstDateForSection(section: indexPath.section)).uppercased()
headerView.label.textColor = headerTextColor
headerView.label.font = headerTextFont
return headerView
default:
fatalError("Unexpected element kind")
Expand Down Expand Up @@ -171,8 +194,8 @@ extension CalendarDateRangePickerViewController : UICollectionViewDelegateFlowLa
}

public func collectionView(_ collectionView: UICollectionView,
layout collectionViewLayout: UICollectionViewLayout,
sizeForItemAt indexPath: IndexPath) -> CGSize {
layout collectionViewLayout: UICollectionViewLayout,
sizeForItemAt indexPath: IndexPath) -> CGSize {
let padding = collectionViewInsets.left + collectionViewInsets.right
let availableWidth = view.frame.width - padding
let itemWidth = availableWidth / CGFloat(itemsPerRow)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@
developmentRegion = English;
hasScannedForEncodings = 0;
knownRegions = (
English,
en,
Base,
);
Expand Down Expand Up @@ -518,7 +519,7 @@
PRODUCT_BUNDLE_IDENTIFIER = "com.miraan.CalendarDateRangePickerViewController-Example";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 5.0;
};
name = Debug;
};
Expand All @@ -534,7 +535,7 @@
PRODUCT_BUNDLE_IDENTIFIER = "com.miraan.CalendarDateRangePickerViewController-Example";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 5.0;
};
name = Release;
};
Expand All @@ -555,7 +556,7 @@
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 5.0;
};
name = Debug;
};
Expand All @@ -572,7 +573,7 @@
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 5.0;
};
name = Release;
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?


func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
internal func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
return true
}
Expand Down
Loading