DateInlineFieldRow.swift 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. // DateInlineFieldRow.swift
  2. // Eureka ( https://github.com/xmartlabs/Eureka )
  3. //
  4. // Copyright (c) 2016 Xmartlabs SRL ( http://xmartlabs.com )
  5. //
  6. //
  7. // Permission is hereby granted, free of charge, to any person obtaining a copy
  8. // of this software and associated documentation files (the "Software"), to deal
  9. // in the Software without restriction, including without limitation the rights
  10. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  11. // copies of the Software, and to permit persons to whom the Software is
  12. // furnished to do so, subject to the following conditions:
  13. //
  14. // The above copyright notice and this permission notice shall be included in
  15. // all copies or substantial portions of the Software.
  16. //
  17. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  20. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  21. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  22. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  23. // THE SOFTWARE.
  24. import Foundation
  25. import UIKit
  26. open class DateInlineCell: Cell<Date>, CellType {
  27. public required init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
  28. super.init(style: style, reuseIdentifier: reuseIdentifier)
  29. }
  30. required public init?(coder aDecoder: NSCoder) {
  31. super.init(coder: aDecoder)
  32. }
  33. open override func setup() {
  34. super.setup()
  35. accessoryType = .none
  36. editingAccessoryType = .none
  37. }
  38. open override func update() {
  39. super.update()
  40. selectionStyle = row.isDisabled ? .none : .default
  41. }
  42. open override func didSelect() {
  43. super.didSelect()
  44. row.deselect()
  45. }
  46. }
  47. open class _DateInlineFieldRow: Row<DateInlineCell>, DatePickerRowProtocol, NoValueDisplayTextConformance {
  48. /// The minimum value for this row's UIDatePicker
  49. open var minimumDate: Date?
  50. /// The maximum value for this row's UIDatePicker
  51. open var maximumDate: Date?
  52. /// The interval between options for this row's UIDatePicker
  53. open var minuteInterval: Int?
  54. /// The formatter for the date picked by the user
  55. open var dateFormatter: DateFormatter?
  56. open var noValueDisplayText: String?
  57. required public init(tag: String?) {
  58. super.init(tag: tag)
  59. dateFormatter = DateFormatter()
  60. dateFormatter?.locale = Locale.current
  61. displayValueFor = { [unowned self] value in
  62. guard let val = value, let formatter = self.dateFormatter else { return nil }
  63. return formatter.string(from: val)
  64. }
  65. }
  66. }