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 @@ -67,7 +67,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 +79,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 +91,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 +103,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 @@ -26,6 +26,7 @@ public class CalendarDateRangePickerViewController: UICollectionViewController {

public var minimumDate: Date!
public var maximumDate: Date!
public var maximumIntervalBetweenDate: Int!

public var selectedStartDate: Date?
public var selectedEndDate: Date?
Expand All @@ -43,7 +44,7 @@ public class CalendarDateRangePickerViewController: UICollectionViewController {
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 +54,20 @@ public class CalendarDateRangePickerViewController: UICollectionViewController {
maximumDate = Calendar.current.date(byAdding: .year, value: 3, to: minimumDate)
}

if maximumIntervalBetweenDate == nil {
maximumIntervalBetweenDate = 36500 // 100 years
}

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
}

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

func didTapDone() {
@objc func didTapDone() {
if selectedStartDate == nil || selectedEndDate == nil {
return
}
Expand Down Expand Up @@ -132,7 +137,7 @@ 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))
return headerView
Expand All @@ -156,7 +161,8 @@ extension CalendarDateRangePickerViewController : UICollectionViewDelegateFlowLa
if selectedStartDate == nil {
selectedStartDate = cell.date
} else if selectedEndDate == nil {
if isBefore(dateA: selectedStartDate!, dateB: cell.date!) {
if isBefore(dateA: selectedStartDate!, dateB: cell.date!)
&& !isOverMaximumDays(dateA: selectedStartDate!, dateB: cell.date!, maxDays: self.maximumIntervalBetweenDate){
selectedEndDate = cell.date
self.navigationItem.rightBarButtonItem?.isEnabled = true
} else {
Expand Down Expand Up @@ -248,4 +254,13 @@ extension CalendarDateRangePickerViewController {
return Calendar.current.compare(dateA, to: dateB, toGranularity: .day) == ComparisonResult.orderedAscending
}

func isOverMaximumDays(dateA: Date, dateB: Date, maxDays: Int) -> Bool {
let diffInDays = Calendar.current.dateComponents([.day], from: dateA, to: dateB).day

if let unwDiffDays = diffInDays {
return unwDiffDays > maxDays
}
return false
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@
TargetAttributes = {
607FACCF1AFB9204008FA782 = {
CreatedOnToolsVersion = 6.3.1;
DevelopmentTeam = 3EKA2B3YUL;
DevelopmentTeam = 89D52653SY;
LastSwiftMigration = 0900;
};
607FACE41AFB9204008FA782 = {
Expand All @@ -230,6 +230,7 @@
developmentRegion = English;
hasScannedForEncodings = 0;
knownRegions = (
English,
en,
Base,
);
Expand Down Expand Up @@ -455,7 +456,7 @@
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 5.0;
};
name = Debug;
};
Expand Down Expand Up @@ -501,7 +502,7 @@
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 5.0;
VALIDATE_PRODUCT = YES;
};
name = Release;
Expand All @@ -511,14 +512,14 @@
baseConfigurationReference = 863F34A79DF14110025EE9E4 /* Pods-CalendarDateRangePickerViewController_Example.debug.xcconfig */;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
DEVELOPMENT_TEAM = 3EKA2B3YUL;
DEVELOPMENT_TEAM = 89D52653SY;
INFOPLIST_FILE = CalendarDateRangePickerViewController/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
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 = 5.0;
};
name = Debug;
};
Expand All @@ -527,14 +528,14 @@
baseConfigurationReference = C9304EBA1ACFB048B6759598 /* Pods-CalendarDateRangePickerViewController_Example.release.xcconfig */;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
DEVELOPMENT_TEAM = 3EKA2B3YUL;
DEVELOPMENT_TEAM = 89D52653SY;
INFOPLIST_FILE = CalendarDateRangePickerViewController/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
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 = 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
Expand Up @@ -14,7 +14,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?


func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
return true
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
{
"images" : [
{
"idiom" : "iphone",
"size" : "20x20",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "20x20",
"scale" : "3x"
},
{
"idiom" : "iphone",
"size" : "29x29",
Expand Down Expand Up @@ -29,10 +39,15 @@
"idiom" : "iphone",
"size" : "60x60",
"scale" : "3x"
},
{
"idiom" : "ios-marketing",
"size" : "1024x1024",
"scale" : "1x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
}
Loading