FUIDatePickerFormCell
@IBDesignable
open class FUIDatePickerFormCell : FUIInlineValidationTableViewCell, FUIPropertyFormCell
A UITableViewCell
subclass, which allows a user to read or enter a value, using a date picker.
The developer should set the following properties on the cell, in their implementation of UITableViewDataSource
cellForRow(at:)
function:
keyName
: The key name of the property.value
: The value of the property, asDate
And an onChangeHandler
:
onChangeHandler
: a handler closure, which is invoked on changes to the value
Optionally, UITableViewController could provide
dateFormatter
: A developer-definedUIDateFormatter
, for transposing betweenDate
type andString
.datePickerMode
: TheUIDatePickerMode
for the date picker. Default is.dateAndTime
. Note that.countDownTimer
mode is not supported. Use theFUIDurationPickerFormCell
for duration values.isEditable
: Indicates if the cell’s value may be modified. Defaults totrue
.
Color setting:
Setting text color of filter buttons for a state using setTintColor(_:for:) api. Currently .disabled
, .normal
and selected
are supported.
cell.setTintColor(UIColor.red, for: .normal)
The following is an example of usage in an application UITableViewController
:
let dateFormatter = DateFormatter()
override func viewDidLoad() {
super.viewDidLoad()
dateFormatter.dateFormat = "dd-MM-yyyy"
self.tableView.register(FUIDatePickerFormCell.self, forCellReuseIdentifier: FUIDatePickerFormCell.reuseIdentifier)
// ...
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: FUIDatePickerFormCell.reuseIdentifier, for: indexPath) as! FUIDatePickerFormCell
cell.keyName = "End Date"
cell.dateFormatter = dateFormatter
cell.datePickerMode = .date
cell.value = cell.dateFormatter.date(from: myObject.endDate) // "02-17-2017"
// MARK: implement onChangeHandler
cell.onChangeHandler = { newValue in
myObject.endDate = cell.dateFormatter.string(from: newValue)
}
return cell
}
Theming
Supported style classes
fdlFUIDatePickerFormCell
fdlFUIDatePickerFormCell_keyLabel
fdlFUIDatePickerFormCell_valueLabel
fdlFUIDatePickerFormCell_selectedBackgroundView
fdlFUIDatePickerFormCell_valueLabel_selected
-
The value type is Date.
Declaration
Swift
public typealias ValueType = Date
-
The value of the property.
Declaration
Swift
open var value: Date { get set }
-
Implementation of change handler. Is invoked on changes to the
value
property.Declaration
Swift
public var onChangeHandler: ((Date) -> Void)?
-
The default cell reuse identifier.
Declaration
Swift
open class var reuseIdentifier: String { get }
-
The UILabel that holds the key name string.
Declaration
Swift
@IBOutlet public private(set) weak var keyLabel: UILabel! { get }
-
The UILabel that holds the value string.
Declaration
Swift
@IBOutlet open private(set) weak var valueLabel: UILabel! { get }
-
Indicates if the value of the cell could be changed or not. The default is true.
Declaration
Swift
open var isEditable: Bool { get set }
-
Indicate whether the slider is enabled.
isEnabled
andisEditable
are in sync.Declaration
Swift
override open var isEnabled: Bool { get set }
-
The key name of the property.
Declaration
Swift
@IBInspectable open var keyName: String? { get set }
-
The
DateFormatter
to be used to display the selectedDate
. Default formatter:- for
UIDatePickerMode.dateAndTime
it is medium date style followed by short time style. - for
UIDatePickerMode.date
it is medium date style - for
UIDatePickerMode.time
it is short time style
Declaration
Swift
open var dateFormatter: DateFormatter? { get set }
- for
-
If
isTrackingLiveChanges
is true, thenonChangeHandler
, will be invoked whenever a date is selected.Otherwise,
onChangeHandler
will be invoked only when the Date Picker is closed.The default value is
true
.Declaration
Swift
open var isTrackingLiveChanges: Bool
-
The
UIDatePickerMode
for theUIDatePicker
for this cell. The default value isUIDatePickerMode.dateAndTime
.Important
important :UIDatePickerMode.countDownTimer
is not allowed here. UseFUIDurationPickerFormCell
for count down mode.Declaration
Swift
open var datePickerMode: UIDatePicker.Mode { get set }
-
The
UIDatePicker
for this cell. It will be displayed only when this cell is selected.Declaration
Swift
@objc public private(set) lazy var datePicker: UIDatePicker { get set }