FUIDatePickerFormCell

@IBDesignable
public class FUIDatePickerFormCell : FUIInlineValidationTableViewCell, FUIPropertyFormCell

A UITableViewCell subclass, which allows a user to read or enter a value, using a date picker.

FUIDatePickerFormCell

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, as Date

And an onChangeHandler:

  • onChangeHandler: a handler closure, which is invoked on changes to the value

Optionally, UITableViewController could provide

  • dateFormatter: A developer-defined UIDateFormatter, for transposing between Date type and String.
  • datePickerMode: The UIDatePickerMode for the date picker. Default is .dateAndTime. Note that .countDownTimer mode is not supported. Use the FUIDurationPickerFormCell for duration values.
  • isEditable: Indicates if the cell’s value may be modified. Defaults to true.

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:

Important

The app’s UITableViewController must subclass FUIFormTableViewController
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_valueTextField
 fdlFUIDatePickerFormCell_selectedBackgroundView
 fdlFUIDatePickerFormCell_valueTextField_selected
  • The value type is Date.

    Declaration

    Swift

    public typealias ValueType = Date
  • The value of the property.

    Declaration

    Swift

    public 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 holds the key name string.

    Declaration

    Swift

    @IBOutlet
    public private(set) weak var keyLabel: UILabel!
  • The UITextField holds the value string.

    Declaration

    Swift

    @IBOutlet
    public private(set) weak var valueTextField: UITextField!
  • Indicates if the value of the cell could be changed or not. The default is true.

    Declaration

    Swift

    public var isEditable: Bool { get set }
  • Indicate whether the slider is enabled. isEnabled and isEditable are in sync.

    Declaration

    Swift

    override public var isEnabled: Bool { get set }
  • The key name of the property.

    Declaration

    Swift

    @IBInspectable
    public var keyName: String? { get set }
  • The placeholder text for the value text field.

    Declaration

    Swift

    @IBInspectable
    public var placeholderText: String? { get set }
  • The text color of placeholder text.

    Declaration

    Swift

    public var placeholderTextColor: UIColor { get set }
  • The DateFormatter to be used to display the selected Date. 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

    public var dateFormatter: DateFormatter? { get set }
  • If isTrackingLiveChanges is true, then onChangeHandler, 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

    public var isTrackingLiveChanges: Bool
  • Undocumented

    Declaration

    Swift

    public var datePickerMode: UIDatePicker.Mode { get set }
  • The UIDatePicker for this cell. It will be displayed only when this cell is selected.

    Declaration

    Swift

    @IBOutlet
    public private(set) weak var datePicker: UIDatePicker!