forked from LoopKit/LoopKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDateAndDurationTableViewCell.swift
More file actions
52 lines (41 loc) · 1.58 KB
/
DateAndDurationTableViewCell.swift
File metadata and controls
52 lines (41 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
//
// DateAndDurationTableViewCell.swift
// LoopKitUI
//
// Copyright © 2018 LoopKit Authors. All rights reserved.
//
import UIKit
public class DateAndDurationTableViewCell: DatePickerTableViewCell {
public weak var delegate: DatePickerTableViewCellDelegate?
@IBOutlet public weak var titleLabel: UILabel!
@IBOutlet public weak var dateLabel: UILabel! {
didSet {
// Setting this color in code because the nib isn't being applied correctly
dateLabel.textColor = .secondaryLabel
}
}
private lazy var durationFormatter: DateComponentsFormatter = {
let formatter = DateComponentsFormatter()
formatter.allowedUnits = [.hour, .minute]
formatter.unitsStyle = .short
return formatter
}()
public override func updateDateLabel() {
switch datePicker.datePickerMode {
case .countDownTimer:
dateLabel.text = durationFormatter.string(from: duration)
case .date:
dateLabel.text = DateFormatter.localizedString(from: date, dateStyle: .medium, timeStyle: .none)
case .dateAndTime:
dateLabel.text = DateFormatter.localizedString(from: date, dateStyle: .short, timeStyle: .short)
case .time:
dateLabel.text = DateFormatter.localizedString(from: date, dateStyle: .none, timeStyle: .medium)
@unknown default:
break // Do nothing
}
}
public override func dateChanged(_ sender: UIDatePicker) {
super.dateChanged(sender)
delegate?.datePickerTableViewCellDidUpdateDate(self)
}
}