Date picker dialog for iOS

Overview

DatePickerDialog 4.0 - iOS - Swift

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

Requirements

DatePickerDialog works on iOS 7, 8 and 9, 10, 11, 12, 13 and 14. It depends on the following Apple frameworks, which should already be included with most Xcode templates:

  • Foundation
  • UIKit

Swift Versions

  • Swift 5.3 (Current)
  • Swift 4.2 (3.0 tag)
  • Swift 4.2 (2.1 tag)
  • Swift 4.2 (2.0 tag)
  • Swift 2.3 (swift_2.3 branch)

Installation

CocoaPods

You can use CocoaPods to install DatePickerDialog by adding it to your Podfile:

platform :ios, '8.0'
use_frameworks!
pod 'DatePickerDialog'

To get the full benefits import DatePickerDialog wherever you import UIKit

import UIKit
import DatePickerDialog

Carthage

Create a Cartfile that lists the framework and run carthage bootstrap. Follow the instructions to add $(SRCROOT)/Carthage/Build/iOS/DatePickerDialogFramework.framework to an iOS project.

github "squimer/DatePickerDialog-iOS-Swift"

Manually

  1. Download and drop DatePickerDialog.swift in your project.
  2. Congratulations!

Example

func datePickerTapped() {
	DatePickerDialog().show(title: "DatePicker", doneButtonTitle: "Done", cancelButtonTitle: "Cancel", datePickerMode: .date) { date in
		if let dt = date {
			let formatter = DateFormatter()
			formatter.dateFormat = "MM/dd/yyyy"
			self.textField.text = formatter.string(from: dt)
		}
	}
}

Dialog parameters

  • showCancelButton: Bool - default true
  • locale: Locale? - default nil

Example without 'Cancel' button:

DatePickerDialog(showCancelButton: false).show(title: "DatePicker", doneButtonTitle: "Done", datePickerMode: .date)

Example with custom locale:

DatePickerDialog(locale: Locale(identifier: "es_PY")).show(title: "DatePicker", doneButtonTitle: "Done", datePickerMode: .date)

Show parameters

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

Special thanks to

License

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

Comments
  • Dialog doesn't appear (XCode 7.3)

    Dialog doesn't appear (XCode 7.3)

    Dialog doesn't appear on my project.

    Dialog view's frame seems to be correct: (0.0, 0.0, 320.0, 568.0)

    Also I tried to bring subview front by adding this line in the func show: method: UIApplication.sharedApplication().windows.first!.bringSubviewToFront(self)

    I'm using a navigation view controller under a tab bar controller. When debugging nothing seems to be wrong. I think it's only a visibility problem.

    Any idea?

    bug 
    opened by m-etka 25
  • Recreated demo project.

    Recreated demo project.

    A bit of restructuring and got the demo project back to work. Reformatted some comments to work with recent Xcode. Closes #33.

    Sry for the huge amount of changes. I recreated the whole demo project and cleaned it up (especially removed localization shizzle and all the AppDelegate stubs to focus only on the actual example invocation of the DatePickerDialog).

    I also created a shared scheme for the DatePickerDialog itself. Now you have all three parts (Sources, Tests and Demo) in one Xcode project. It is also more feasible to write unit tests and directly see the changes in the demo application.

    Cheers!

    invalid 
    opened by benjohnde 12
  • DatePicker does not dismiss keyboard

    DatePicker does not dismiss keyboard

    I have a simple view that has 2 text fields. The first text field takes normal input via the keyboard, the second textfield is my date field. When I when I tap on the date field when the keyboard is already showing the date picker dialogbox shows but the keyboard is not dismissed. I've tried to dismiss the keyboard via "view.endEditing(true)" and also firstTextField.resignFirstResponder() but nothing works. On some devices the keyboard covers the date picker dialogbox which leaves the user in a state where they have to force quit the app.

    opened by dreed47 6
  • added fix to maintain datepicker dialog view on orientation change

    added fix to maintain datepicker dialog view on orientation change

    Fix maintains datepicker dialog view on orientation change. However, date selected after orientation change in not always set (sometimes date is set to default date even though different date is selected)

    opened by PramodJoshi 5
  • First Responder.. / Resign

    First Responder.. / Resign

    When the textField is tapped once, it works fine, but after canceling or selecting a date, if I want to modify the date and tap on the textField, the picker does not come up again. I have to select a different textField in order for it to work again.

    opened by jhoanarango 3
  • DatePickerDialog don't show when setting entry point programmatically

    DatePickerDialog don't show when setting entry point programmatically

    Hello everybody!

    I have a big problem and hope one of you can help me. When I open my App the first time, with the entry point from the storyboard, everything works fine. But when I open it the second time, where I set the entry point trough the AppDelegate class the dialog don't appear on the screen. I've seen a issue where someone had a similar problem, but there was no solution for this.

    Thanks in advance!

    opened by gruenekampfente 3
  • Change the datePicker access control

    Change the datePicker access control

    This pull request changes the access control of the datePicker attribute so that it is possible to customise the Date Picker like for instance defining a maximum and minimum date.

    opened by diogoguimaraes 3
  • Support ios9 Multitasking

    Support ios9 Multitasking

    In SplitView Mode on iOS9

    UIScreen.mainScreen().bounds delivers the size of the screen. But we want the size of the app.

    You can use UIScreen.mainScreen().applicationFrame instead of UIScreen.mainScreen().bounds

    btw: i think you forgot to add a listener to the cancel button ;-)

    self.cancelButton.addTarget(self, action: "buttonTapped:", forControlEvents: UIControlEvents.TouchUpInside)

    best regards Alex

    bug enhancement 
    opened by digitaldesaster 3
  • dialog not centered in landscape mode

    dialog not centered in landscape mode

    thanks for fixing the orientation crash. i tested your example project in the ios simulator (iPhone6, iPad Air 2). In landscape mode the dialog is not centered.

    best regards Alex

    bug 
    opened by digitaldesaster 3
  • Deprecated warning in xcode 8.3

    Deprecated warning in xcode 8.3

    ..../Pods/DatePickerDialog/Sources/DatePickerDialog.swift:107:77: 'M_PI' is deprecated: Please use 'Double.pi' or '.pi' to get the value of correct type and avoid casting.

    opened by jcrooke 2
  • iOS 15 preferredDatePickerStyle inline Time not working

    iOS 15 preferredDatePickerStyle inline Time not working

    iOS 14 is working fine..issues come out when upgrade to iOS 15

    Date are working fine, but the time tapped, but no respond.. unable to select other time.. minDate set today, maxDate set one year later

    if #available(iOS 14.0, *) { self.datePicker.preferredDatePickerStyle = .inline DispatchQueue.main.async { self.datePicker.setValue(UIColor.red, forKey: "textColor") } } IMG_3035

    IMG_3036

    opened by kienwei518 0
Releases(4.0)
Owner
Squimer
Squimer
A SwiftUI List Picker to replace system Picker in List

BetterListPicker An alternative customizable list picker in order to replace built-in non customizable Picker when we write settings view codes. Demo

Jinya 1 Apr 11, 2022
A better SwiftUI Picker Use _Picker instead of Picker

BetterPicker A better SwiftUI Picker. Use _Picker instead of Picker. Create styles with _PickerStyle. The is a WIP This library is currently a work-in

Eric Lewis 17 Dec 14, 2022
:date: UIDatePicker modally presented with iOS 7 custom transitions.

AIDatePickerController Installation Manually Download and drop /AIDatePickerControllerfolder in your project. Congratulations! Usage // Create a date

Ali Karagoz 90 Sep 23, 2022
FYPhoto is a photo/video picker and image browser library for iOS written in pure Swift. It is feature-rich and highly customizable to match your App's requirements.

FYPhoto is a photo/video picker and image browser library for iOS written in pure Swift. It is feature-rich and highly customizable to match your App's requirements.

null 10 Dec 11, 2022
a picker view shown as a popup for iOS in Objective-C

CZPicker Demo Change Log 3 most recent changes are listed here. Full change logs v0.4.3 - 2016-08-12 Added - (void)czpickerViewWillDisplay:(CZPickerVi

Chen Zeyu 527 Oct 2, 2022
An iOS picker view to serve all your "picking" needs

Mandoline The PickerView is a UICollectionView that provides a smooth "picking" interface. In order to get the most out of it, a consuming view contro

Blue Apron 883 Nov 28, 2022
A country picker view controller for iOS

Planet A country picker view controller for iOS. Installation CocoaPods You can use CocoaPods to install Planet by adding it to your Podfile: platform

kWallet 71 Jul 11, 2022
Multi-picker for iOS and Mac available in SwiftUI

Multi-picker for iOS and Mac available in Swift UI

1amageek 5 Jul 12, 2022
iOS/macOS media picker for importing images and videos in SwiftUI

iOS/macOS media picker for importing images and videos in SwiftUI.

Mobile Development Club 13 Dec 30, 2022
🎯 Swift country and phone code Picker

CountryPicker Picker code Swift 3 / 4 / 5. Example To run the example project, clone the repo, and run pod install from the Example directory first. U

null 207 Dec 22, 2022
MICountryPicker is a country picker controller for iOS8+ with an option to search.

MICountryPicker MICountryPicker is a country picker controller for iOS8+ with an option to search. The list of countries is based on the ISO 3166 coun

Mustafa Ibrahim 90 Mar 27, 2021
A drop in single image picker.

PHSingleImagePicker A low memory, single image picker wrapper that provide a significant smaller file size while also preserve high image quality. Int

Phanith NY 0 Nov 6, 2021
A simple yet customizable horizontal and vertical picker view

WheelPicker A simple yet customizable horizontal and vertical picker view Features Vertical or Horizontal picker Image or Text data Configure UILabel

Mind Studios 74 Sep 26, 2022
React-native-place-picker: Pick any place with single click 🚀

React-native-place-picker: Pick any place with single click ??

b0iq 59 Dec 29, 2022
A SwiftUI implementation of a picker that also allows direct input.

ComboPicker ComboPicker is a SwiftUI view that allows users to input a value by selecting from a predefined set or by typing a custom one. Installatio

Alessio Moiso 5 Sep 13, 2022
LocationPicker - A ready for use and fully customizable location picker for your app

LocationPicker A ready for use and fully customizable location picker for your app. Features Installation Cocoapods Carthage Swift Package Manager Qui

Zhuoran 397 Nov 16, 2022
Quickly reproduce the dropdown UIPickerView / ActionSheet functionality on iOS.

ActionSheetPicker-3.0 Important update Now I fixed most of the things and merge PR' (thanks to ). I did much work to support this library from iOS 5.

Petr Korolev 3.4k Dec 21, 2022
A simple, customizable view for efficiently collecting country information in iOS apps.

CountryPickerView CountryPickerView is a simple, customizable view for selecting countries in iOS apps. You can clone/download the repository and run

Kizito Nwose 459 Dec 27, 2022