blob: 9b59b082263c37d6955aeb5ca9af1d8c025e2200 (
plain)
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
|
//
// CheckableSettingsCell.swift
// MullvadVPN
//
// Created by Jon Petersson on 2023-06-05.
// Copyright © 2025 Mullvad VPN AB. All rights reserved.
//
import UIKit
class CheckableSettingsCell: SettingsCell {
let checkboxView = CheckboxView()
var isEnabled = true {
didSet {
titleLabel.isEnabled = isEnabled
}
}
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
setCheckboxView()
selectedBackgroundView?.backgroundColor = .clear
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func prepareForReuse() {
super.prepareForReuse()
setCheckboxView()
}
override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
checkboxView.isChecked = selected
}
override func applySubCellStyling() {
super.applySubCellStyling()
contentView.layoutMargins.left = 0
}
private func setCheckboxView() {
setLeadingView { superview in
superview.addConstrainedSubviews([checkboxView]) {
checkboxView.centerYAnchor.constraint(equalTo: superview.centerYAnchor)
checkboxView.pinEdgesToSuperview(
PinnableEdges([
.leading(0),
.trailing(UIMetrics.SettingsCell.checkableSettingsCellLeftViewSpacing),
]))
}
}
}
}
|