ExpirationReminderDateTableViewCell.swift 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. //
  2. // ExpirationReminderDateTableViewCell.swift
  3. // OmniKitUI
  4. //
  5. // Created by Pete Schwamb on 4/11/19.
  6. // Copyright © 2019 Pete Schwamb. All rights reserved.
  7. //
  8. import Foundation
  9. import LoopKitUI
  10. public class ExpirationReminderDateTableViewCell: DatePickerTableViewCell {
  11. public weak var delegate: DatePickerTableViewCellDelegate?
  12. @IBOutlet public weak var titleLabel: UILabel! {
  13. didSet {
  14. // Setting this color in code because the nib isn't being applied correctly
  15. if #available(iOSApplicationExtension 13.0, *) {
  16. titleLabel?.textColor = .label
  17. }
  18. }
  19. }
  20. @IBOutlet public weak var dateLabel: UILabel! {
  21. didSet {
  22. // Setting this color in code because the nib isn't being applied correctly
  23. if #available(iOSApplicationExtension 13.0, *) {
  24. dateLabel?.textColor = .secondaryLabel
  25. }
  26. switch effectiveUserInterfaceLayoutDirection {
  27. case .leftToRight:
  28. dateLabel?.textAlignment = .right
  29. case .rightToLeft:
  30. dateLabel?.textAlignment = .left
  31. @unknown default:
  32. dateLabel?.textAlignment = .right
  33. }
  34. }
  35. }
  36. var maximumDate: Date? {
  37. set {
  38. datePicker.maximumDate = newValue
  39. }
  40. get {
  41. return datePicker.maximumDate
  42. }
  43. }
  44. var minimumDate: Date? {
  45. set {
  46. datePicker.minimumDate = newValue
  47. }
  48. get {
  49. return datePicker.minimumDate
  50. }
  51. }
  52. private lazy var formatter: DateFormatter = {
  53. let formatter = DateFormatter()
  54. formatter.timeStyle = .short
  55. formatter.dateStyle = .medium
  56. formatter.doesRelativeDateFormatting = true
  57. return formatter
  58. }()
  59. public override func updateDateLabel() {
  60. dateLabel.text = formatter.string(from: date)
  61. }
  62. public override func dateChanged(_ sender: UIDatePicker) {
  63. super.dateChanged(sender)
  64. delegate?.datePickerTableViewCellDidUpdateDate(self)
  65. }
  66. }
  67. extension ExpirationReminderDateTableViewCell: NibLoadable { }