SquereCheckBox.swift
1.61 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
//
// SquereCheckBox.swift
// InterQR-Internship
//
// Created by Дмитрий Тимофеев on 17.06.2022.
//
import UIKit
class SquereCheckbox: UIButton {
private let checkboxImageView: UIImageView = {
let obj = UIImageView()
return obj
}()
private let checkBoxLabel: UILabel = {
let obj = UILabel()
obj.font = .skModernist(type: .regular, ofSize: 12)
return obj
}()
override var isSelected: Bool {
didSet {
checkBoxLabel.textColor = isSelected ?
.TextColor.darkBlue :
.TextColor.lightGrey
checkboxImageView.image = isSelected ?
UIImage(named: .Image.fullSquere) :
UIImage(named: .Image.emptySquere)
}
}
var checkboxTitle: String = "" {
didSet {
checkBoxLabel.text = checkboxTitle
}
}
override init(frame: CGRect) {
super.init(frame: frame)
setup()
}
required init?(coder: NSCoder) {
super.init(coder: coder)
setup()
}
private func setup() {
isSelected = false
addSubview(checkboxImageView)
addSubview(checkBoxLabel)
checkboxImageView.snp.makeConstraints { make in
make.leading.equalToSuperview()
make.top.bottom.equalToSuperview()
}
checkBoxLabel.snp.makeConstraints { make in
make.top.bottom.equalToSuperview()
make.trailing.equalToSuperview()
make.leading.equalTo(checkboxImageView.snp.trailing).offset(10)
}
}
}