From eee6d382c34c9e7ac64282492dfbfa6ac13b5d88 Mon Sep 17 00:00:00 2001 From: Alexookah Date: Mon, 23 Dec 2019 18:11:38 +0200 Subject: [PATCH 1/3] added Cancelable --- Sources/DatePickerDialog.swift | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/Sources/DatePickerDialog.swift b/Sources/DatePickerDialog.swift index 78d2611..e864e7c 100644 --- a/Sources/DatePickerDialog.swift +++ b/Sources/DatePickerDialog.swift @@ -4,6 +4,8 @@ import UIKit private extension Selector { static let buttonTapped = #selector(DatePickerDialog.buttonTapped) static let deviceOrientationDidChange = #selector(DatePickerDialog.deviceOrientationDidChange) + static let viewForCancelTapped = #selector(DatePickerDialog.viewForCancelTapped) + } open class DatePickerDialog: UIView { @@ -27,6 +29,7 @@ open class DatePickerDialog: UIView { private var datePickerMode: UIDatePicker.Mode? private var callback: DatePickerCallback? var showCancelButton: Bool = false + var cancelable: Bool = false var locale: Locale? private var textColor: UIColor! @@ -38,13 +41,14 @@ open class DatePickerDialog: UIView { buttonColor: UIColor = UIColor.blue, font: UIFont = .boldSystemFont(ofSize: 15), locale: Locale? = nil, - showCancelButton: Bool = true) { + showCancelButton: Bool = true, cancelable: Bool = false) { let size = UIScreen.main.bounds.size super.init(frame: CGRect(x: 0, y: 0, width: size.width, height: size.height)) self.textColor = textColor self.buttonColor = buttonColor self.font = font self.showCancelButton = showCancelButton + self.cancelable = cancelable self.locale = locale setupView() } @@ -227,6 +231,11 @@ open class DatePickerDialog: UIView { // Add the buttons addButtonsToView(container: container) + + if cancelable { + let tap = UITapGestureRecognizer(target: self, action: .viewForCancelTapped) + self.addGestureRecognizer(tap) + } return container } @@ -300,6 +309,11 @@ open class DatePickerDialog: UIView { close() } + + // triggered when view is tapped + @objc func viewForCancelTapped() { + close() + } deinit { NotificationCenter.default.removeObserver(self) From 20f7f5e6e23bd6d5081440976a9599ff358c9ce2 Mon Sep 17 00:00:00 2001 From: Alex Lykesas Date: Mon, 23 Dec 2019 19:07:45 +0200 Subject: [PATCH 2/3] Update README.mdown --- README.mdown | 1 + 1 file changed, 1 insertion(+) diff --git a/README.mdown b/README.mdown index 599477a..8173745 100644 --- a/README.mdown +++ b/README.mdown @@ -61,6 +61,7 @@ github "squimer/DatePickerDialog-iOS-Swift" ## Dialog parameters - showCancelButton: Bool - default true +- cancelable: Bool - default true - locale: Locale? - default nil Example without 'Cancel' button: From a9eb1590b8d34cc6b6ee62b12235348e948ca712 Mon Sep 17 00:00:00 2001 From: Alexookah Date: Mon, 23 Dec 2019 19:08:35 +0200 Subject: [PATCH 3/3] cancelabel default true --- Sources/DatePickerDialog.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/DatePickerDialog.swift b/Sources/DatePickerDialog.swift index e864e7c..fdd0f5c 100644 --- a/Sources/DatePickerDialog.swift +++ b/Sources/DatePickerDialog.swift @@ -41,7 +41,7 @@ open class DatePickerDialog: UIView { buttonColor: UIColor = UIColor.blue, font: UIFont = .boldSystemFont(ofSize: 15), locale: Locale? = nil, - showCancelButton: Bool = true, cancelable: Bool = false) { + showCancelButton: Bool = true, cancelable: Bool = true) { let size = UIScreen.main.bounds.size super.init(frame: CGRect(x: 0, y: 0, width: size.width, height: size.height)) self.textColor = textColor