forked from LoopKit/LoopKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLevelHUDView.swift
More file actions
54 lines (43 loc) · 1.22 KB
/
LevelHUDView.swift
File metadata and controls
54 lines (43 loc) · 1.22 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
53
54
//
// LevelHUDView.swift
// Loop
//
// Created by Nate Racklyeft on 2/4/17.
// Copyright © 2017 LoopKit Authors. All rights reserved.
//
import UIKit
open class LevelHUDView: BaseHUDView {
@IBOutlet public weak var levelMaskView: LevelMaskView!
override open func awakeFromNib() {
super.awakeFromNib()
updateColor()
accessibilityValue = LocalizedString("Unknown", comment: "Accessibility value for an unknown value")
}
override open func stateColorsDidUpdate() {
super.stateColorsDidUpdate()
updateColor()
}
open func updateColor() {
levelMaskView.tintColor = nil
switch level {
case .none:
tintColor = stateColors?.unknown
case let x? where x > 0.25:
tintColor = stateColors?.normal
case let x? where x > 0.10:
tintColor = stateColors?.warning
levelMaskView.tintColor = stateColors?.warning
default:
tintColor = stateColors?.error
}
}
public var level: Double? {
didSet {
levelMaskView.value = level ?? 1.0
levelDidChange()
}
}
open func levelDidChange() {
updateColor()
}
}