forked from LoopKit/Loop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStatusHighlightHUDView.swift
More file actions
74 lines (62 loc) · 2.16 KB
/
StatusHighlightHUDView.swift
File metadata and controls
74 lines (62 loc) · 2.16 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
//
// StatusHighlightHUDView.swift
// LoopUI
//
// Created by Nathaniel Hamming on 2020-06-05.
// Copyright © 2020 LoopKit Authors. All rights reserved.
//
import UIKit
public class StatusHighlightHUDView: UIView, NibLoadable {
private var stackView: UIStackView!
@IBOutlet public weak var messageLabel: UILabel!
@IBOutlet public weak var icon: UIImageView! {
didSet {
icon.tintColor = tintColor
}
}
public enum IconPosition {
case left
case right
}
private var iconPosition: IconPosition = .right {
didSet {
stackView.removeArrangedSubview(messageLabel)
stackView.removeArrangedSubview(icon)
switch iconPosition {
case .left:
stackView.addArrangedSubview(icon)
stackView.addArrangedSubview(messageLabel)
messageLabel.textAlignment = .left
case .right:
stackView.addArrangedSubview(messageLabel)
stackView.addArrangedSubview(icon)
messageLabel.textAlignment = .right
}
}
}
public override init(frame: CGRect) {
super.init(frame: frame)
setup()
}
public required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
setup()
}
func setup() {
stackView = (StatusHighlightHUDView.nib().instantiate(withOwner: self, options: nil)[0] as! UIStackView)
stackView.translatesAutoresizingMaskIntoConstraints = false
self.addSubview(stackView)
// Use AutoLayout to have the stack view fill its entire container.
NSLayoutConstraint.activate([
stackView.centerXAnchor.constraint(equalTo: centerXAnchor),
stackView.centerYAnchor.constraint(equalTo: centerYAnchor),
stackView.widthAnchor.constraint(equalTo: widthAnchor),
stackView.heightAnchor.constraint(equalTo: heightAnchor),
])
}
public func setIconPosition(_ iconPosition: IconPosition) {
if self.iconPosition != iconPosition {
self.iconPosition = iconPosition
}
}
}