forked from LoopKit/LoopKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOverrideHistoryCollectionViewCell.swift
More file actions
79 lines (64 loc) · 2.28 KB
/
OverrideHistoryCollectionViewCell.swift
File metadata and controls
79 lines (64 loc) · 2.28 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
75
76
77
78
//
// OverrideHistoryCollectionViewCell.swift
// LoopKitUI
//
// Created by Anna Quinlan on 8/6/20.
// Copyright © 2020 LoopKit Authors. All rights reserved.
//
import UIKit
final class OverrideHistoryCollectionViewCell: UICollectionViewCell, IdentifiableClass {
@IBOutlet weak var titleLabel: UILabel!
private lazy var overlayDimmerView: UIView = {
let view = UIView()
if #available(iOSApplicationExtension 13.0, *) {
view.backgroundColor = .systemBackground
} else {
view.backgroundColor = .white
}
view.alpha = 0
view.translatesAutoresizingMaskIntoConstraints = false
return view
}()
override func awakeFromNib() {
super.awakeFromNib()
let selectedBackgroundView = UIView()
self.selectedBackgroundView = selectedBackgroundView
if #available(iOSApplicationExtension 13.0, iOS 13.0, *) {
selectedBackgroundView.backgroundColor = .tertiarySystemFill
backgroundColor = .secondarySystemGroupedBackground
layer.cornerCurve = .continuous
} else {
selectedBackgroundView.backgroundColor = UIColor.lightGray.withAlphaComponent(0.3)
backgroundColor = .white
}
layer.cornerRadius = 16
addSubview(overlayDimmerView)
NSLayoutConstraint.activate([
overlayDimmerView.leadingAnchor.constraint(equalTo: leadingAnchor),
overlayDimmerView.trailingAnchor.constraint(equalTo: trailingAnchor),
overlayDimmerView.topAnchor.constraint(equalTo: topAnchor),
overlayDimmerView.bottomAnchor.constraint(equalTo: bottomAnchor)
])
}
override func prepareForReuse() {
removeOverlay(animated: false)
}
func applyOverlayToFade(animated: Bool) {
if animated {
UIView.animate(withDuration: 0.3, animations: {
self.overlayDimmerView.alpha = 0.5
})
} else {
self.overlayDimmerView.alpha = 0.5
}
}
func removeOverlay(animated: Bool) {
if animated {
UIView.animate(withDuration: 0.3, animations: {
self.overlayDimmerView.alpha = 0
})
} else {
self.overlayDimmerView.alpha = 0
}
}
}