/DatePickerDialog-iOS-Swift

Date picker dialog for iOS

Primary LanguageSwiftMIT LicenseMIT

DatePickerDialog - iOS - Swift

DatePickerDialog is an iOS drop-in classe that displays an UIDatePicker within an UIAlertView.

Requirements

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

Adding DatePickerDialog to your project

You can directly add the DatePickerDialog.swift file to your project.

  1. Download the latest code version or add the repository as a git submodule to your git-tracked project.
  2. 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.

Example

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)"
		}
	}

}

Show parameters

  • title: String (Required)
  • doneButtonTitle: String
  • cancelButtonTitle: String
  • defaultDate: NSDate
  • datePickerMode: UIDatePickerMode (Required)
  • callback: ((date: NSDate) -> Void) (Required)

Todo

  • Handle device orientation changes.

Special thanks to

License

This code is distributed under the terms and conditions of the MIT license.