CNLiveHomeLanmuCell.swift
3.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
//
// CNLiveHomeLanmuCell.swift
// metaCode
//
// Created by zx on 2025/2/20.
//
import Foundation
typealias CNLiveHomeLanmuImgClickBlock = (_ imgModel:CNLiveDownSlideContentsModel)->Void;
class CNLiveHomeLanmuCell:UITableViewCell{
var imgClickBlock : CNLiveHomeLanmuImgClickBlock?
//slideModel
var _slideModel : CNLiveDownSlideModel?
var slideModel : CNLiveDownSlideModel? {
get{
_slideModel
}
set{
_slideModel = newValue!
for obj in contentView.subviews{
if obj.tag > 100{
obj.removeFromSuperview()
}
}
self.setupNewUI(model: slideModel!)
}
}
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
self.selectionStyle = .none
setupUI()
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
private func setupUI() {
contentView.backgroundColor = .clear
self.backgroundColor = .clear
self.contentView.clipsToBounds = true
}
func setupNewUI(model:CNLiveDownSlideModel){
var showNum:Int = model.contents.count>=4 ? 4 : model.contents.count
for (idx,mdl) in model.contents.enumerated(){
if idx >= 4 { break}
let leftPadding:CGFloat = 30.0
let imgWH:CGFloat = 44.0
let jianJuPadding:CGFloat = (KSreenWidth-2*leftPadding-CGFloat(showNum)*imgWH)/CGFloat(showNum-1)
let imgX:CGFloat = leftPadding+CGFloat(idx)*(imgWH+jianJuPadding)
let imgY:CGFloat = 0.0
let iconImgView = UIImageView(frame: CGRect(x: imgX, y: imgY, width: imgWH, height: imgWH))
iconImgView.contentMode = .scaleAspectFill
iconImgView.tag = 1000+idx
iconImgView.kf.setImage(with: URL(string: mdl.poster))
iconImgView.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(iconImgViewAction)))
iconImgView.isUserInteractionEnabled = true
self.contentView.addSubview(iconImgView)
let titleLbl = UILabel(frame: CGRect(x: 0, y: iconImgView.bottom+2.5, width: 50, height: 20))
titleLbl.centerX = iconImgView.centerX
titleLbl.font = Font_15
titleLbl.textColor = HexColor("#000102")
titleLbl.text = mdl.title
titleLbl.tag = 1000+idx
self.contentView.addSubview(titleLbl)
titleLbl.snp.makeConstraints { make in
make.centerX.equalTo(iconImgView.snp.centerX)
make.top.equalTo(iconImgView.snp.bottom).offset(2.5)
}
}
}
@objc func iconImgViewAction(ges: UITapGestureRecognizer){
showLoading(message: "")
let imageView = ges.view as! UIImageView
let index = imageView.tag-1000
if let slideModel = self.slideModel?.contents[index]{
self.imgClickBlock?(slideModel)
}
}
}