MeetingFormDatePickerCell.swift 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. //
  2. // MeetingFormDatePickerCell.swift
  3. // O2Platform
  4. //
  5. // Created by FancyLou on 2020/11/25.
  6. // Copyright © 2020 zoneland. All rights reserved.
  7. //
  8. import UIKit
  9. import Eureka
  10. class MeetingFormDatePickerCell: Cell<Date>, CellType {
  11. @IBOutlet weak var dateLabel: UILabel!
  12. override func setup() {
  13. super.setup()
  14. selectionStyle = .none
  15. }
  16. override func update() {
  17. super.update()
  18. if let v = row.value {
  19. self.dateLabel.text = v.toString("yyyy-MM-dd")
  20. }
  21. }
  22. override func didSelect() {
  23. // 点击事件
  24. var defaultDate = Date()
  25. if let v = row.value {
  26. defaultDate = v
  27. }
  28. self.showDatePicker(pickerStyle: .yearMonthDay, callBackResult: { (result) in
  29. self.row.value = result
  30. self.dateLabel.text = result.toString("yyyy-MM-dd")
  31. }, defaultDate: defaultDate)
  32. }
  33. private func showDatePicker(pickerStyle: DateStyle, callBackResult:((_ result:Date) -> Void)?, defaultDate: Date = Date()) {
  34. let datePicker = DatePickerView.datePicker(style: pickerStyle, scrollToDate: defaultDate) { date in
  35. guard let date = date else { return }
  36. if let cr = callBackResult {
  37. cr(date)
  38. }
  39. }
  40. datePicker.show()
  41. }
  42. }
  43. final class MeetingFormDatePickerRow: Row<MeetingFormDatePickerCell>, RowType {
  44. required init(tag: String?) {
  45. super.init(tag: tag)
  46. cellProvider = CellProvider<MeetingFormDatePickerCell>(nibName: "MeetingFormDatePickerCell")
  47. }
  48. }