ResidentTableViewCell.swift
5.47 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
//
// ResidentTableViewCell.swift
// InterQR-Internship
//
// Created by Дмитрий Тимофеев on 21.06.2022.
//
import UIKit
class ResidentTableViewCell: UITableViewCell {
static let id = String(describing: ResidentTableViewCell.self)
var containerView: UIView = {
var obj = UIView()
obj.layer.cornerRadius = 15
obj.layer.borderWidth = 1
obj.layer.borderColor = .BorderColor.lightGrey
return obj
}()
var serialNumberView: UIImageView = {
let obj = UIImageView()
obj.clipsToBounds = true
obj.layer.cornerRadius = 21.5
return obj
}()
var serialNumberLabel: UILabel = {
let obj = UILabel()
obj.font = .skModernist(type: .bold, ofSize: 14)
obj.textColor = .white
return obj
}()
var nameLabel: UILabel = {
var obj = UILabel()
obj.textColor = .TextColor.darkBlue
obj.font = .skModernist(type: .bold, ofSize: 16)
obj.text = "John Doe"
return obj
}()
var phoneNumberLabel: UILabel = {
var obj = UILabel()
obj.textColor = .TextColor.lightGrey
obj.font = .skModernist(type: .regular, ofSize: 14)
obj.text = "+38095"
return obj
}()
var managerButton: SquereCheckbox = {
var obj = SquereCheckbox()
obj.checkboxTitle = .Text.manager
obj.setTitleColor(.TextColor.lightGrey, for: .normal)
obj.setTitleColor(.TextColor.darkBlue, for: .selected)
obj.isSelected = false
return obj
}()
var hiddenButton: SquereCheckbox = {
var obj = SquereCheckbox()
obj.checkboxTitle = .Text.hidden
obj.setTitleColor(.TextColor.lightGrey, for: .normal)
obj.setTitleColor(.TextColor.darkBlue, for: .selected)
obj.isSelected = false
return obj
}()
var heartButton: UIButton = {
var obj = UIButton()
obj.setImage(UIImage(named: .Image.heart), for: .normal)
obj.setImage(UIImage(named: .Image.heartRed), for: .selected)
return obj
}()
var removeCellButton: UIButton = {
var obj = UIButton()
obj.setImage(UIImage(named: .Image.bin), for: .normal)
return obj
}()
var gradientBG: CAGradientLayer = {
let obj = CAGradientLayer()
var leftColor = UIColor.GradientBlue.left
var rightColor = UIColor.GradientBlue.right
obj.colors = [leftColor, rightColor]
obj.startPoint = CGPoint(x: 0, y: 0.5)
obj.endPoint = CGPoint(x: 1, y: 0.5)
return obj
}()
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
setup()
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
func setup() {
selectionStyle = .none
serialNumberView.layer.insertSublayer(gradientBG, at: 0)
contentView.addSubview(containerView)
containerView.addSubview(serialNumberView)
serialNumberView.addSubview(serialNumberLabel)
containerView.addSubview(nameLabel)
containerView.addSubview(phoneNumberLabel)
containerView.addSubview(managerButton)
containerView.addSubview(hiddenButton)
containerView.addSubview(heartButton)
containerView.addSubview(removeCellButton)
containerView.snp.makeConstraints {
$0.leading.trailing.equalToSuperview().inset(25)
$0.bottom.top.equalToSuperview().inset(8)
}
serialNumberView.snp.makeConstraints {
$0.height.width.equalTo(41)
$0.leading.equalToSuperview().offset(23)
$0.top.equalToSuperview().offset(19)
}
serialNumberLabel.snp.makeConstraints {
$0.centerX.centerY.equalToSuperview()
}
nameLabel.snp.makeConstraints {
$0.leading.equalTo(serialNumberView.snp.trailing).offset(18)
$0.top.equalToSuperview().offset(22)
}
removeCellButton.snp.makeConstraints {
$0.centerY.equalTo(nameLabel.snp.centerY)
$0.trailing.equalToSuperview().offset(-22.5)
}
phoneNumberLabel.snp.makeConstraints {
$0.leading.equalTo(nameLabel.snp.leading)
$0.top.equalTo(nameLabel.snp.bottom).offset(1)
}
managerButton.snp.makeConstraints {
$0.top.equalTo(phoneNumberLabel.snp.bottom).offset(30)
$0.leading.equalToSuperview().offset(24)
$0.height.equalTo(20)
}
hiddenButton.snp.makeConstraints {
$0.leading.equalTo(managerButton.snp.trailing).offset(23)
$0.centerY.equalTo(managerButton)
$0.height.equalTo(20)
}
heartButton.snp.makeConstraints {
$0.centerY.equalTo(hiddenButton)
$0.bottom.equalToSuperview().offset(-18)
$0.trailing.equalToSuperview().offset(-22)
}
}
override func layoutSubviews() {
super.layoutSubviews()
gradientBG.frame = serialNumberView.bounds
}
func model(_ item: ResidentModel) {
nameLabel.text = item.name
phoneNumberLabel.text = item.mobileNumber
managerButton.isSelected = item.manager
hiddenButton.isSelected = item.hidden
heartButton.isSelected = item.heart
}
}