OOFormDateItemView.swift 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. //
  2. // OOFormDateItemView.swift
  3. // o2app
  4. //
  5. // Created by 刘振兴 on 2018/1/25.
  6. // Copyright © 2018年 zone. All rights reserved.
  7. //
  8. import UIKit
  9. class OOFormDateItemView: OOFormBaseView,OOFormConfigEnable {
  10. @IBOutlet weak var titleNameLabel: UILabel!
  11. @IBOutlet weak var valueTextField: UITextField!
  12. @IBOutlet weak var showValueLabel: UILabel!
  13. override func awakeFromNib() {
  14. showValueLabel.isHidden = true
  15. valueTextField.delegate = self
  16. }
  17. override init(frame: CGRect) {
  18. super.init(frame: frame)
  19. }
  20. required init?(coder aDecoder: NSCoder) {
  21. super.init(coder: aDecoder)
  22. }
  23. func configItem(_ model: OOFormBaseModel) {
  24. self.model = model
  25. titleNameLabel.text = self.model?.titleName
  26. if self.model?.itemStatus! == .read {
  27. showValueLabel.isHidden = false
  28. showValueLabel.text = (self.model?.callbackValue ) as? String
  29. valueTextField.isHidden = true
  30. }else{
  31. showValueLabel.isHidden = true
  32. //showValueLabel.text = (self.model?.callbackValue ) as? String
  33. valueTextField.isHidden = false
  34. if let v = self.model?.callbackValue, let vDate = v as? Date {
  35. valueTextField.text = vDate.toString("yyyy-MM-dd")
  36. }
  37. }
  38. }
  39. }
  40. extension OOFormDateItemView:UITextFieldDelegate {
  41. func textFieldShouldBeginEditing(_ textField: UITextField) -> Bool {
  42. UIApplication.shared.keyWindow?.endEditing(true) //关闭输入法
  43. let date = self.model?.callbackValue as? Date ?? Date()
  44. self.showDatePicker(pickerStyle: .yearMonthDay, callBackResult: { (theDate) in
  45. textField.text = theDate.toString("yyyy-MM-dd")
  46. self.model?.callbackValue = theDate
  47. }, defaultDate: date)
  48. return false
  49. }
  50. }