ExpandingDatePicker is a textual date picker that will expand to show a graphical date picker beneath it when focused. It has the same styling as the expandable date picker Apple uses in Calendar.app.
ExpandingDatePicker is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'ExpandingDatePicker'
ExpandingDatePicker
extends NSDatePicker
so the API is the same. Only catch is that it only works for year/month/day elements, in single picker mode and in the textField
style.
import ExpandingDatePicker
…
let datePicker = ExpandingDatePicker(frame: .zero)
// Required settings...
datePicker.datePickerElements = .yearMonthDay
datePicker.datePickerMode = .single
datePicker.datePickerStyle = .textField
datePicker.sizeToFit()
…
view.addSubview(datePicker)
Use the Library to add a Date Picker to your view. In the Identity Inspector panel, set the custom class to ExpandingDatePicker
.
Deployment target of macOS 10.10+, though it has only been tested on 10.14.
- When the field expands to show the graphical date picker, you'll notice that the traffic lights in your app's window will turn gray. The expansion is shown in an
NSPanel
(a special kind ofNSWindow
), and when that panel temporarily becomes the app's key window, the traffic lights go dark. Calendar.app's version of this expanded date picker doesn't have this problem because they use a private API.
Fred Potter, fpotter@gmail.com
ExpandingDatePicker is available under the MIT license. See the LICENSE file for more info.