Class
DatePicker
public final class DatePicker: UIView, JTACMonthViewDataSource, JTACMonthViewDelegate,
UIPickerViewDelegate, UIPickerViewDataSource
Date pickers let users select a date, or a range of dates. DatePickers are created with a configuration.
Prefer to use make(configuration:didSelectDates:)
to create a DatePicker.
The configuration allows you to configure some parts of how the DatePicker works. The most useful options are startDate, endDate, startAtDate, allowsMultipleSelection and useRangeSelection. You can generally ignore any others and leave them set to their defaults.
You can put the DatePicker almost anywhere as it is just a UIView. Adding it as a Card's content section may be useful if you need a header or actions.
Relationships
Conforms To
JTACMonthViewDataSource
JTACMonthViewDelegate
UIPickerViewDataSource
UIPickerViewDelegate
UIView
Initializers
init(configuration:didSelectDates:)
public init(configuration: DatePickerConfiguration, didSelectDates: @escaping ([Date]) -> Void)
Creates a new DatePicker with a configuration.
Prefer to use make(configuration:didSelectDates:)
instead of this method.
Depending on the configuration, the didSelectDates closure may contain one date, or multiple dates.
In the case where only single selection is allowed, the closure can be called multiple times, where the user may have made a selection, updated their selection, or deselected a date (this will return an empty array).
In the case where allowsMultipleSelection is true, but useRangeSelection is false, this closure will be called multiple times, once for each selection/deselection, and will return all the current selected dates.
In the case where useRangeSelection is true, all dates in the range will be returned.
Parameters
Name | Type | Description |
---|---|---|
configuration | DatePickerConfiguration |
The configuration object to initialize the DatePicker. |
didSelectDates | @escaping ([Date]) -> Void |
A closure that will be called when the user selects a date. |
Methods
make(configuration:didSelectDates:)
public static func make(configuration: DatePickerConfiguration, didSelectDates: @escaping ([Date]) -> Void) -> DatePicker
Creates a new DatePicker with a configuration.
Depending on the configuration, the didSelectDates closure may contain one date, or multiple dates.
In the case where only single selection is allowed, the closure can be called multiple times, where the user may have made a selection, updated their selection, or deselected a date (this will return an empty array).
In the case where allowsMultipleSelection is true, but useRangeSelection is false, this closure will be called multiple times, once for each selection/deselection, and will return all the current selected dates.
In the case where useRangeSelection is true, all dates in the range will be returned.
Parameters
Name | Type | Description |
---|---|---|
configuration | DatePickerConfiguration |
The configuration object to initialize the DatePicker. |
didSelectDates | @escaping ([Date]) -> Void |
A closure that will be called when the user selects a date. |
configureCalendar(_:)
public func configureCalendar(_ calendar: JTACMonthView) -> ConfigurationParameters
calendar(_:cellForItemAt:cellState:indexPath:)
public func calendar(_ calendar: JTACMonthView, cellForItemAt date: Date,
cellState: CellState, indexPath: IndexPath) -> JTACDayCell
calendar(_:willDisplay:forItemAt:cellState:indexPath:)
public func calendar(_ calendar: JTACMonthView, willDisplay cell: JTACDayCell,
forItemAt date: Date, cellState: CellState, indexPath: IndexPath)
calendar(_:willScrollToDateSegmentWith:)
public func calendar(_ calendar: JTACMonthView, willScrollToDateSegmentWith visibleDates: DateSegmentInfo)
calendar(_:didScrollToDateSegmentWith:)
public func calendar(_ calendar: JTACMonthView, didScrollToDateSegmentWith visibleDates: DateSegmentInfo)
calendar(_:didSelectDate:cell:cellState:indexPath:)
public func calendar(_ calendar: JTACMonthView, didSelectDate date: Date,
cell: JTACDayCell?, cellState: CellState, indexPath: IndexPath)
calendar(_:didDeselectDate:cell:cellState:indexPath:)
public func calendar(_ calendar: JTACMonthView, didDeselectDate date: Date,
cell: JTACDayCell?, cellState: CellState, indexPath: IndexPath)
calendar(_:shouldSelectDate:cell:cellState:indexPath:)
public func calendar(_ calendar: JTACMonthView, shouldSelectDate date: Date,
cell: JTACDayCell?, cellState: CellState,
indexPath: IndexPath) -> Bool
calendar(_:shouldDeselectDate:cell:cellState:indexPath:)
public func calendar(_ calendar: JTACMonthView, shouldDeselectDate date: Date,
cell: JTACDayCell?, cellState: CellState, indexPath: IndexPath) -> Bool
numberOfComponents(in:)
func numberOfComponents(in pickerView: UIPickerView) -> Int
pickerView(_:numberOfRowsInComponent:)
func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int
pickerView(_:titleForRow:forComponent:)
func pickerView(_ pickerView: UIPickerView, titleForRow row: Int,
forComponent component: Int) -> String?
pickerView(_:didSelectRow:inComponent:)
func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int,
inComponent component: Int)