CNLivePlayletHomePageHeaderCell.swift
14.5 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
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
//
// CNLivePlayletHomePageHeaderCell.swift
// metaCode
//
// Created by zx on 2024/1/4.
// 短剧主页-头视图Cell
import Foundation
import QMUIKit
import SwiftUI
import SnapKit
import Kingfisher
//cell高度变化
typealias homePageHeaderCellChangedBlockActionBlock = (_ cell: CNLivePlayletHomePageHeaderCell ,_ jianjieHeight:CGFloat) -> Void
class CNLivePlayletHomePageHeaderCell:UITableViewCell{
var homePageHeaderCellChangedBlock:homePageHeaderCellChangedBlockActionBlock?
var _albumListModel : CNLiveAlbumListModel?
var albumListModel : CNLiveAlbumListModel? {
get{
_albumListModel
}
set{
_albumListModel = newValue!
self.setupNewUI(model: _albumListModel!)
}
}
//MARK: - 懒加载
lazy var iconImgView :UIImageView = {
let iconImgView = UIImageView(frame: CGRect(x: 20, y: 20, width: 112, height: 147))
iconImgView.layer.cornerRadius = 5
iconImgView.clipsToBounds = true
return iconImgView
}()
lazy var payIconImgView :UIImageView = {
let payIconImgView = UIImageView(frame: CGRect(x: 0, y: 0, width: 30, height: 14))
payIconImgView.image = UIImage(named: "homePage_payment")
return payIconImgView
}()
///标题
lazy var titleLabl: UILabel = {
let titleLabel = UILabel.init(frame: CGRectMake(self.iconImgView.right+15, self.iconImgView.top, KSreenWidth-(self.iconImgView.right+15)-10, 21))
titleLabel.textColor = HexColor("#333333")
titleLabel.textAlignment = .left
titleLabel.font = BoldFont_15
titleLabel.text = "啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊"
let height = titleLabel.qmui_lineHeight
titleLabel.height = height
return titleLabel
}()
///集数
lazy var jishuLabel: UILabel = {
let titleLabel = UILabel.init(frame: CGRectMake(self.titleLabl.left, self.titleLabl.bottom+20, KSreenWidth-(self.iconImgView.right+15)-10, 21))
titleLabel.textColor = HexColor("#999999")
titleLabel.textAlignment = .left
titleLabel.font = Font_12
titleLabel.text = "45集"
let height = titleLabel.qmui_lineHeight
titleLabel.height = height
return titleLabel
}()
///简介
lazy var jianjieLabel: UILabel = {
let titleLabel = UILabel.init(frame: CGRectMake(self.iconImgView.left, self.iconImgView.bottom+10, KSreenWidth-2*self.iconImgView.left, 21))
titleLabel.textColor = HexColor("#333333")
titleLabel.textAlignment = .left
titleLabel.font = Font_12
titleLabel.backgroundColor = UIColor(red:0.98, green:0.98, blue:0.98, alpha:1.00)
titleLabel.text = "啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈啊哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈啊哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈啊哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈啊哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈啊哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈"
titleLabel.numberOfLines = 0
var lines = titleLabel.getRealLabelTextLines()
let height = titleLabel.qmui_lineHeight
if lines > 2 {
lines = 2
}
titleLabel.height = height*CGFloat(lines)
return titleLabel
}()
//展开,收起
lazy var expandBtn: UIButton = {
let expandBtn = UIButton.init(type: .custom)
expandBtn.backgroundColor = .white
expandBtn.frame = CGRect(x: self.jianjieLabel.right-60, y: self.jianjieLabel.bottom, width: 60, height: 30)
expandBtn.setTitle("展开", for: .normal)
expandBtn.setTitle("收起", for: .selected)
expandBtn.setTitleColor(HexColor("#666666"), for: .normal)
expandBtn.setImage(UIImage(named: "homepage_unfold"), for: .normal)
expandBtn.setImage(UIImage(named: "homepage_fold"), for: .selected)
expandBtn.titleLabel?.font = Font_12
expandBtn.setupButtonImageAndTitlePossitionWith(padding: 5, style: .right)
expandBtn.addTarget(self, action: #selector(expandBtnAction), for: .touchUpInside)
return expandBtn
}()
//追剧|已追剧
lazy var followBtn: UIButton = {
let followBtn = UIButton(type: .custom)
followBtn.setTitle("追剧", for: .normal)
followBtn.setTitleColor(HexColor("#FFFFFF"), for: .normal)
followBtn.titleLabel?.font = Font_15
followBtn.layer.cornerRadius = 20
followBtn.clipsToBounds = true
followBtn.addTarget(self, action: #selector(followBtnAction), for: .touchUpInside)
let gradient = CAGradientLayer()
gradient.frame = self.bounds
gradient.colors = [HexColor("#FFD20B")!.cgColor, HexColor("#FFA81A")!.cgColor]
gradient.locations = [0, 1]
gradient.startPoint = CGPoint(x: 0.96, y: 0.42)
gradient.endPoint = CGPoint(x: 0.42, y: 0.42)
gradient.name = "followBtnSubLayer"
followBtn.layer.insertSublayer(gradient, at: 0)
// #FDF4E4
return followBtn
}()
//付费解锁全集|已购买
lazy var paymentBtn: UIButton = {
let paymentBtn = UIButton(type: .custom)
paymentBtn.setTitle("付费解锁全集", for: .normal)
paymentBtn.setTitleColor(HexColor("#FFFFFF"), for: .normal)
paymentBtn.setTitle("已购买", for: .selected)
paymentBtn.setTitleColor(HexColor("#619CFF"), for: .selected)
paymentBtn.titleLabel?.font = Font_15
paymentBtn.layer.cornerRadius = 20
paymentBtn.clipsToBounds = true
paymentBtn.addTarget(self, action: #selector(paymentBtnAction), for: .touchUpInside)
let gradient = CAGradientLayer()
gradient.frame = self.bounds
gradient.colors = [HexColor("#67C5FF")!.cgColor, HexColor("#609AFF")!.cgColor]
gradient.locations = [0, 1]
gradient.startPoint = CGPoint(x: 0, y: 0.5)
gradient.endPoint = CGPoint(x: 0.5, y: 0.5)
paymentBtn.layer.insertSublayer(gradient, at: 0)
// #ECF3FF
return paymentBtn
}()
///全部剧集
lazy var allJuJiLabl: UILabel = {
let allJuJiLabl = UILabel.init(frame: CGRectMake(self.iconImgView.right+15, self.followBtn.bottom+20, 100, 16))
allJuJiLabl.textColor = HexColor("#333333")
allJuJiLabl.textAlignment = .left
allJuJiLabl.font = BoldFont_16
allJuJiLabl.text = "全部剧集"
return allJuJiLabl
}()
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
self.selectionStyle = .none
self.setUI()
}
func setUI(){
self.contentView.addSubview(self.iconImgView)
self.iconImgView.addSubview(self.payIconImgView)
self.contentView.addSubview(self.titleLabl)
self.contentView.addSubview(self.jishuLabel)
self.contentView.addSubview(self.jianjieLabel)
self.contentView.addSubview(self.expandBtn)
self.contentView.addSubview(self.followBtn)
self.contentView.addSubview(self.paymentBtn)
self.contentView.addSubview(self.allJuJiLabl)
let lines = jianjieLabel.getRealLabelTextLines()
if lines <= 2{
self.expandBtn.isHidden = true
}else{
self.expandBtn.isHidden = false
}
self.followBtn.snp.makeConstraints { make in
make.top.equalTo(self.jianjieLabel.snp.bottom).offset(25)
make.left.equalTo(self.iconImgView.snp.left)
make.width.equalTo(140)
make.height.equalTo(40)
}
self.paymentBtn.snp.makeConstraints { make in
make.top.equalTo(self.followBtn)
make.left.equalTo(self.followBtn.snp.right).offset(15)
make.right.equalTo(self.contentView.snp.right).offset(-15)
make.height.equalTo(40)
}
self.allJuJiLabl.snp.makeConstraints { make in
make.top.equalTo(self.followBtn.snp.bottom).offset(20)
make.left.equalTo(self.iconImgView.snp.left)
make.width.equalTo(100)
make.height.equalTo(16)
}
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
func setupNewUI(model:CNLiveAlbumListModel){
self.titleLabl.text = model.albumMsgModel?.albumName ?? "专辑名称"
self.jishuLabel.text = String(format: "共%@集",model.albumMsgModel?.episodeNow ?? "1")
self.iconImgView.kf.setImage(with: URL(string: model.albumMsgModel?.albumImg ?? ""))
if model.product?.albumProductType == "0"{
//免费
self.payIconImgView.isHidden = true
}else if model.product?.albumProductType == "1"{
//积分
self.payIconImgView.isHidden = false
}else if model.product?.albumProductType == "2"{
//付费
self.payIconImgView.isHidden = false
}else{
self.payIconImgView.isHidden = false
}
self.jianjieLabel.text = (model.albumMsgModel?.desc != "") ? model.albumMsgModel?.desc : "啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈啊哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈啊哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈啊哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈啊哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈啊哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈"//"短剧简介"
var lines = jianjieLabel.getRealLabelTextLines()
let height = jianjieLabel.qmui_lineHeight
if lines <= 2{
self.expandBtn.isHidden = true
}else{
self.expandBtn.isHidden = false
}
if self.expandBtn.isSelected{
//展开状态
self.jianjieLabel.height = height*CGFloat(lines)
}else{
//收起状态
self.jianjieLabel.height = 2*height
}
if model.albumMsgModel!.collection{
//已追剧
self.followBtn.setTitleColor(HexColor("#F5A623"), for: .normal)
self.followBtn.setTitle("已追剧", for: .normal)
self.followBtn.isUserInteractionEnabled = false
let follLayer = self.followBtn.layer.qmui_layer(withName: "followBtnSubLayer")
follLayer?.removeFromSuperlayer()
self.followBtn.backgroundColor = HexColor("#FDF4E4")
}else{
//未追剧
self.followBtn.setTitle("追剧", for: .normal)
self.followBtn.setTitleColor(HexColor("#FFFFFF"), for: .normal)
self.followBtn.isUserInteractionEnabled = true
let follLayer = self.followBtn.layer.qmui_layer(withName: "followBtnSubLayer")
if (follLayer != nil){
//已添加layer
}else{
//未添加layer
let gradient = CAGradientLayer()
gradient.frame = self.bounds
gradient.colors = [HexColor("#FFD20B")!.cgColor, HexColor("#FFA81A")!.cgColor]
gradient.locations = [0, 1]
gradient.startPoint = CGPoint(x: 0.96, y: 0.42)
gradient.endPoint = CGPoint(x: 0.42, y: 0.42)
gradient.name = "followBtnSubLayer"
followBtn.layer.insertSublayer(gradient, at: 0)
self.followBtn.backgroundColor = .clear
}
}
}
// MARK: - Action
@objc func expandBtnAction(button:UIButton){
button.isSelected = !button.isSelected
let lines = jianjieLabel.getRealLabelTextLines()
let height = jianjieLabel.qmui_lineHeight
if button.isSelected{
//文本收起状态,点击展开
self.jianjieLabel.height = CGFloat(lines)*height
}else{
//文本展开状态,点击收起
self.jianjieLabel.height = 2*height
}
self.homePageHeaderCellChangedBlock!(self, self.jianjieLabel.height)
self.expandBtn.top = self.jianjieLabel.bottom
}
@objc func followBtnAction(button:UIButton){
//网络请求追剧
CNLiveHomePageViewModel.postAlbumCollect(aid: self.albumListModel?.albumMsgModel?.albumId ?? "", type: 1) { result, status in
if status == .success{
self.followBtn.setTitleColor(HexColor("#F5A623"), for: .normal)
self.followBtn.setTitle("已追剧", for: .normal)
self.followBtn.isUserInteractionEnabled = false
let follLayer = self.followBtn.layer.qmui_layer(withName: "followBtnSubLayer")
follLayer?.removeFromSuperlayer()
self.followBtn.backgroundColor = HexColor("#FDF4E4")
}else{
}
}
}
@objc func paymentBtnAction(button:UIButton){
button.isSelected = !button.isSelected
}
}