DatePickerDialog is an iOS drop-in classe that displays an UIDatePicker within an UIAlertView.
DatePickerDialog works on iOS 7 and 8. It depends on the following Apple frameworks, which should already be included with most Xcode templates:
- Foundation
- UIKit
- QuartzCore
You can directly add the DatePickerDialog.swift
file to your project.
- Download the latest code version or add the repository as a git submodule to your git-tracked project.
- Open your project in Xcode, then drag and drop
DatePickerDialog.swift
onto your project (use the "Product Navigator view"). Make sure to select Copy items when asked if you extracted the code archive outside of your project.
class ViewController: UIViewController {
@IBOutlet weak var textField: UITextField!
override func viewDidLoad() {
super.viewDidLoad()
}
/* IBActions */
@IBAction func datePickerTapped(sender: AnyObject) {
DatePickerDialog().show(title: "DatePicker", doneButtonTitle: "Done", cancelButtonTitle: "Cancel", datePickerMode: .Date) {
(date) -> Void in
self.textField.text = "\(date)"
}
}
}
- title: String (Required)
- doneButtonTitle: String
- cancelButtonTitle: String
- defaultDate: NSDate
- datePickerMode: UIDatePickerMode (Required)
- callback: ((date: NSDate) -> Void) (Required)
- Handle device orientation changes.
- @wimagguc for the work with ios-custom-alertview library.
This code is distributed under the terms and conditions of the MIT license.