Skip to content

Kautenja/UIPopupDatePicker

Repository files navigation

UIPopupDatePicker

swift-badge carthage-badge

Screenshots

With Time Picker

Without Time Picker

Requirements

This framework relies on (and installs):

Installation

Carthage

Add the following to your Cartfile

github "kautenja/UIPopupDatePicker" ~> 1.1

Example

To run the example project, clone the repo, and build it on devices of you choosing.

Code Usage

Creation

The main entry point for UIPopupDatePicker is the static show method.

_ = UIPopupDatePicker.show(on: self, with: nil, block: nil)

Customization

This function returns an instance of UIPopupDatePicker in case you might want to manipulate some of the controller manually:

let popup = UIPopupDatePicker.show(on: self, with: nil, block: nil)
popup.headerText = "Some text you might want as a title!"

Callback

To respond to a change in the date use the callback handler:

_ = UIPopupDatePicker.show(on: self, with: Date()) { (selected) in
    NSLog("UIPopupDatePicker returned \(selected) in the callback")
}

the parameter passed to the anonymous function an optional date (Date?). If the user:

  1. presses done

the callback will be executed with the date from the calendar and time from the picker. If the time picker is hidden, the time will be the time that the popup was first created.

  1. presses clear

the callback will be executed passing nil as the parameter to the anonymous function. Use this to remove a date from something.

  1. presses cancel

the callback IS NOT executed and the popup dismisses with no changes to the parent view controller.

Code Samples

see ViewController for a production example of how this might come together

Author

Kautenja, kautencreations@gmail.com

License

TL;DR do what you want with it.

UIPopupDatePicker is available under the MIT license. See the LICENSE file for more info.