forked from LoopKit/LoopKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCustomOverrideCollectionViewCell.swift
More file actions
68 lines (55 loc) · 1.92 KB
/
CustomOverrideCollectionViewCell.swift
File metadata and controls
68 lines (55 loc) · 1.92 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
//
// CustomOverrideCollectionViewCell.swift
// LoopKitUI
//
// Created by Michael Pangburn on 11/5/19.
// Copyright © 2019 LoopKit Authors. All rights reserved.
//
import UIKit
final class CustomOverrideCollectionViewCell: UICollectionViewCell, IdentifiableClass {
@IBOutlet weak var titleLabel: UILabel!
private lazy var overlayDimmerView: UIView = {
let view = UIView()
view.backgroundColor = .systemBackground
view.alpha = 0
view.translatesAutoresizingMaskIntoConstraints = false
return view
}()
override func awakeFromNib() {
super.awakeFromNib()
let selectedBackgroundView = UIView()
self.selectedBackgroundView = selectedBackgroundView
selectedBackgroundView.backgroundColor = .tertiarySystemFill
backgroundColor = .secondarySystemGroupedBackground
layer.cornerCurve = .continuous
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
}
}
}