-
Notifications
You must be signed in to change notification settings - Fork 356
/
SelectableSettingsCell.swift
54 lines (45 loc) · 1.51 KB
/
SelectableSettingsCell.swift
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
//
// SelectableSettingsCell.swift
// MullvadVPN
//
// Created by Jon Petersson on 2023-05-08.
// Copyright © 2023 Mullvad VPN AB. All rights reserved.
//
import UIKit
class SelectableSettingsCell: SettingsCell {
let tickImageView: UIImageView = {
let imageView = UIImageView(image: UIImage(named: "IconTick"))
imageView.contentMode = .center
imageView.tintColor = .white
imageView.alpha = 0
return imageView
}()
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
setTickView()
selectedBackgroundView?.backgroundColor = UIColor.Cell.Background.selected
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func prepareForReuse() {
super.prepareForReuse()
setTickView()
}
override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
tickImageView.alpha = selected ? 1 : 0
}
private func setTickView() {
setLeadingView { superview in
superview.addConstrainedSubviews([tickImageView]) {
tickImageView.pinEdgesToSuperview(PinnableEdges([
.leading(0),
.trailing(UIMetrics.SettingsCell.selectableSettingsCellLeftViewSpacing),
.top(0),
.bottom(0),
]))
}
}
}
}