HustleScoreCell.swift
9.1 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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
//
// HustleScoreCell.swift
// AoleiSports
//
// Created by ilCode on 2024/6/24.
//
import UIKit
/// 球队技术统计cell
class HustleScoreCell: BaseTableViewCell {
static let reuseIdentifier = "HustleScoreCell"
private lazy var bgView: UIView = {
let view = UIView()
view.backgroundColor = kWhite
view.corners(radius: 8)
view.border(borderColor: UIColor.colorWith(hexString: "E9EAEF"), borderWidth: 1)
view.layer.shadowColor = UIColor.colorWith(hexString: "E9EAEF").cgColor
view.layer.shadowOffset = CGSize(width: 0, height: 0.5)
view.layer.shadowOpacity = 0.3
view.layer.shadowRadius = 8
view.layer.masksToBounds = false
return view
}()
private lazy var hostNameLab: UILabel = {
let lab = UILabel()
lab.textAlignment = .center
lab.font = kBoldFontSize(16)
lab.textColor = kMainTitleColor
lab.numberOfLines = 2
return lab
}()
private lazy var gameLab: UILabel = {
let lab = UILabel()
lab.textAlignment = .center
lab.font = kBoldFontSize(14)
lab.textColor = kMainTitleColor
return lab
}()
private lazy var guestNameLab: UILabel = {
let lab = UILabel()
lab.textAlignment = .center
lab.font = kBoldFontSize(16)
lab.textColor = kMainTitleColor
lab.numberOfLines = 2
return lab
}()
private lazy var teamGameStackView: UIStackView = {
let stackView = UIStackView(arrangedSubviews: [hostNameLab, gameLab, guestNameLab])
stackView.axis = .horizontal
stackView.alignment = .center
stackView.distribution = .fillEqually
stackView.spacing = 2
return stackView
}()
private lazy var matchTimeLab: UILabel = {
let lab = UILabel()
lab.textAlignment = .center
lab.font = kFontSize(14)
lab.textColor = kMidTitleColor
return lab
}()
private lazy var atackView: HostGuestSkillView = {
let aView = HostGuestSkillView(skillType: .attack)
return aView
}()
private lazy var statusView: HostGuestSkillView = {
let aView = HostGuestSkillView(skillType: .status)
return aView
}()
private lazy var techView: HostGuestSkillView = {
let aView = HostGuestSkillView(skillType: .tech)
return aView
}()
private lazy var freeLab: UILabel = {
let lab = UILabel()
lab.text = "免费查看"
lab.textAlignment = .center
lab.font = kFontSize(14)
lab.textColor = UIColor.colorWith(hexString: "D8B47A")
return lab
}()
var model: HadoopMatchModel? {
didSet {
hostNameLab.text = model?.hostName
gameLab.text = model?.comName
guestNameLab.text = model?.awayName
matchTimeLab.text = ScoreTools.getFormatMatchTime(time: model?.matchTime, format: "MM-dd HH:mm")
if let hostModel = model?.homeData, let guestModel = model?.awayData {
atackView.update(hostValue: hostModel.attackTotal, guestValue: guestModel.attackTotal)
statusView.update(hostValue: hostModel.statusScore, guestValue: guestModel.statusScore)
techView.update(hostValue: hostModel.techScore, guestValue: guestModel.techScore)
}
}
}
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
backgroundColor = kMainBgColor
contentView.addSubview(bgView)
bgView.addSubview(teamGameStackView)
bgView.addSubview(matchTimeLab)
bgView.addSubview(atackView)
bgView.addSubview(statusView)
bgView.addSubview(techView)
bgView.addSubview(freeLab)
bgView.snp.makeConstraints { make in
make.top.equalToSuperview()
make.left.equalToSuperview().offset(5)
make.right.equalToSuperview().offset(-5)
make.bottom.equalToSuperview().offset(-5)
}
teamGameStackView.snp.makeConstraints { make in
make.top.equalToSuperview().offset(10)
make.left.right.equalToSuperview()
}
matchTimeLab.snp.makeConstraints { make in
make.top.equalTo(teamGameStackView.snp.bottom).offset(5)
make.left.equalToSuperview().offset(5)
make.right.equalToSuperview().offset(-5)
}
atackView.snp.makeConstraints { make in
make.top.equalTo(matchTimeLab.snp.bottom).offset(5)
make.left.equalToSuperview().offset(20)
make.right.equalToSuperview().offset(-20)
make.height.equalTo(20)
}
statusView.snp.makeConstraints { make in
make.top.equalTo(atackView.snp.bottom).offset(5)
make.left.right.height.equalTo(atackView)
}
techView.snp.makeConstraints { make in
make.top.equalTo(statusView.snp.bottom).offset(5)
make.left.right.height.equalTo(atackView)
}
freeLab.snp.makeConstraints { make in
make.top.equalTo(techView.snp.bottom).offset(5)
make.left.equalToSuperview().offset(5)
make.right.equalToSuperview().offset(-5)
make.bottom.equalToSuperview().offset(-10)
}
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
class HostGuestSkillView: UIStackView {
enum SkillType {
case attack
case status
case tech
}
private lazy var hostAttackLab: UILabel = {
let lab = UILabel()
lab.font = kFontSize(14)
lab.textColor = kMidTitleColor
return lab
}()
private lazy var hostProgressView: UIProgressView = {
let proView = UIProgressView()
proView.trackTintColor = .clear
proView.corners(radius: 2)
proView.transform = CGAffineTransform(rotationAngle: .pi)
return proView
}()
private lazy var hostStackView: UIStackView = {
let stackView = UIStackView(arrangedSubviews: [hostAttackLab, hostProgressView])
stackView.axis = .horizontal
stackView.alignment = .center
stackView.distribution = .fill
stackView.spacing = 10
return stackView
}()
private lazy var skillStatusLab: UILabel = {
let lab = UILabel()
lab.textAlignment = .center
lab.font = kFontSize(14)
lab.textColor = kMidTitleColor
return lab
}()
private lazy var guestProgressView: UIProgressView = {
let proView = UIProgressView()
proView.trackTintColor = .clear
proView.corners(radius: 2)
return proView
}()
private lazy var guestAttackLab: UILabel = {
let lab = UILabel()
lab.textAlignment = .right
lab.font = kFontSize(14)
lab.textColor = kMidTitleColor
return lab
}()
private lazy var guestStackView: UIStackView = {
let stackView = UIStackView(arrangedSubviews: [guestProgressView, guestAttackLab])
stackView.axis = .horizontal
stackView.alignment = .center
stackView.distribution = .fill
stackView.spacing = 10
return stackView
}()
private lazy var skillStackView: UIStackView = {
let stackView = UIStackView(arrangedSubviews: [hostStackView, skillStatusLab, guestStackView])
stackView.axis = .horizontal
stackView.alignment = .center
stackView.distribution = .fill
stackView.spacing = 20
return stackView
}()
init(skillType: SkillType) {
super.init(frame: .zero)
addSubview(skillStackView)
skillStackView.snp.makeConstraints { make in
make.edges.equalToSuperview()
}
skillStatusLab.snp.makeConstraints { make in
make.centerX.equalToSuperview()
}
hostProgressView.snp.makeConstraints { make in
make.height.equalTo(6)
}
guestProgressView.snp.makeConstraints { make in
make.height.equalTo(6)
}
var progressTintColor = UIColor.colorWith(hexString: "2FA3ED")
var skillStatus = "进攻"
if skillType == .status {
progressTintColor = UIColor.colorWith(hexString: "8BC8F5")
skillStatus = "状态"
} else if skillType == .tech {
progressTintColor = UIColor.colorWith(hexString: "C5E3F9")
skillStatus = "技术"
}
hostProgressView.progressTintColor = progressTintColor
guestProgressView.progressTintColor = progressTintColor
skillStatusLab.text = skillStatus
}
required init(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
func update(hostValue: Int?, guestValue: Int?) {
hostAttackLab.text = "\(hostValue ?? 0)"
guestAttackLab.text = "\(guestValue ?? 0)"
hostProgressView.progress = Float(hostValue ?? 0) / Float(100)
guestProgressView.progress = Float(guestValue ?? 0) / Float(100)
}
}