CNLiveVodShopExpandCell.swift
5.46 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
//
// CNLiveVodShopExpandCell.swift
// metaCode
//
// Created by zx on 2025/3/21.
//
import Foundation
class CNLiveVodShopExpandCell: UITableViewCell {
//
var _vodPlayShopModel : [CNLiveVodPlayShopModel]?
var vodPlayShopModel : [CNLiveVodPlayShopModel]? {
get{
_vodPlayShopModel
}
set{
_vodPlayShopModel = newValue!
for obj in contentView.subviews{
if obj.tag > 100{
obj.removeFromSuperview()
}
}
setupNewUI(model: _vodPlayShopModel!)
}
}
//MARK: - 懒加载
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
self.selectionStyle = .none
contentView.backgroundColor = .white
contentView.clipsToBounds = true
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
func setupNewUI(model:[CNLiveVodPlayShopModel]){
//总显示块数/循环数
let totalNum = model.count
//lieIndex 当前是contents的第0列还是第1列
var lieIndex = 0
//hangIndex 当前是第几行,1...n
var hangIndex = 1
let imgWH = (KSreenWidth-15*3)*0.5
let bottomH = 55.0
let rowH = imgWH+bottomH+15.0
for i in 0..<totalNum{//i是第几行
if lieIndex == 0{
//显示左边的块
let contentMdl = model[(hangIndex-1)*2+(lieIndex)]
let imageView = UIImageView(frame: CGRectMake(DownSlideRecommendLeftGap, CGFloat(hangIndex-1)*rowH, CGFloat(imgWH), CGFloat(imgWH)))
imageView.kf.setImage(with: URL(string:contentMdl.img))
imageView.tag = i+1000
imageView.layer.cornerRadius = 9
imageView.clipsToBounds = true
imageView.contentMode = .scaleAspectFill
imageView.isUserInteractionEnabled = true
imageView.addGestureRecognizer(UITapGestureRecognizer.init(target: self, action: #selector(imgTapAction)))
contentView.addSubview(imageView)
let titleStr = contentMdl.title
let subTitleStr = "¥\(contentMdl.price)"
let titleLbl = UILabel(frame: CGRect(x: imageView.left, y: imageView.bottom+10, width: imageView.width, height: 21))
titleLbl.font = BoldFont_15
titleLbl.textColor = HexColor("#333333")
titleLbl.text = titleStr
titleLbl.tag = i+1000
contentView.addSubview(titleLbl)
let subTitleLbl = UILabel(frame: CGRect(x: titleLbl.left, y: titleLbl.bottom, width: titleLbl.width, height: 24))
subTitleLbl.font = Font_17
subTitleLbl.textColor = HexColor("#E56E32")
subTitleLbl.text = subTitleStr
subTitleLbl.tag = i+1000
contentView.addSubview(subTitleLbl)
lieIndex = 1
}else{
//lieIndex==1显示右边的块
let contentMdl = model[(hangIndex-1)*2+(lieIndex)]
let imageView = UIImageView(frame: CGRectMake(CGFloat(DownSlideRecommendLeftGap*2)+CGFloat(imgWH), CGFloat(hangIndex-1)*rowH, CGFloat(imgWH), CGFloat(imgWH)))
imageView.kf.setImage(with: URL(string:contentMdl.img))
imageView.tag = i+1000
imageView.layer.cornerRadius = 14
imageView.clipsToBounds = true
imageView.contentMode = .scaleAspectFill
imageView.isUserInteractionEnabled = true
imageView.addGestureRecognizer(UITapGestureRecognizer.init(target: self, action: #selector(imgTapAction)))
contentView.addSubview(imageView)
let titleStr = contentMdl.title
let subTitleStr = "¥\(contentMdl.price)"
let titleLbl = UILabel(frame: CGRect(x: imageView.left, y: imageView.bottom+10, width: imageView.width, height: 21))
titleLbl.font = BoldFont_15
titleLbl.textColor = HexColor("#333333")
titleLbl.text = titleStr
titleLbl.tag = i+1000
contentView.addSubview(titleLbl)
let subTitleLbl = UILabel(frame: CGRect(x: titleLbl.left, y: titleLbl.bottom, width: titleLbl.width, height: 24))
subTitleLbl.font = Font_17
subTitleLbl.textColor = HexColor("#E56E32")
subTitleLbl.tag = i+1000
subTitleLbl.text = subTitleStr
contentView.addSubview(subTitleLbl)
lieIndex = 0
hangIndex += 1
}
}
}
@objc func imgTapAction(ges: UITapGestureRecognizer){
let imageView = ges.view as! UIImageView
let i = imageView.tag-1000
let contentMdl = (self.vodPlayShopModel?[i])!
let urlString = "https://managemall.cnlive.com/html/mall/1/#/pages/main/detail/detail?"+"id=\(contentMdl.id)&uid=\(UserInfoManager.shared.userInfo.uid)"
CNLiveDownSlideTool.pushWebAndVodVCWithContentsMdl(model: kCNDownSlideContentsModelModelProduct , contentId: "" , pid: "" , shareUrl: "" , thirdUrl: urlString , title: contentMdl.title , s_to: "" ,trailerId: "" , controller: nil, slideModel: nil)
}
}