CNLiveVodTrailerExpandCell.swift
4.59 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
//
// CNLiveVodTrailerExpandCell.swift
// metaCode
//
// Created by zx on 2025/3/20.
// 看点展开cell
import Foundation
class CNLiveVodTrailerExpandCell:UITableViewCell{
var isJiShuSelected = false//是否选中
var _vodPlayBlockListListModel : CNLiveVodPlayBlockListListModel?
var vodPlayBlockListListModel : CNLiveVodPlayBlockListListModel? {
get{
_vodPlayBlockListListModel
}
set{
_vodPlayBlockListListModel = newValue!
self.setupNewUI(model: _vodPlayBlockListListModel!)
}
}
//MARK: - 懒加载
lazy var iconImgView :UIImageView = {
let iconImgView = UIImageView()
iconImgView.contentMode = .scaleAspectFill
iconImgView.clipsToBounds = true
iconImgView.layer.cornerRadius = 9
return iconImgView
}()
lazy var titleLabel: UILabel = {
let titleLbl = UILabel()
titleLbl.font = BoldFont_14
titleLbl.textColor = HexColor("#333333")
titleLbl.text = "标题"
return titleLbl
}()
lazy var subTitleLabel: UILabel = {
let titleLbl = UILabel()
titleLbl.font = Font_12
titleLbl.textColor = HexColor("#999999")
titleLbl.text = "副标题"
return titleLbl
}()
//付费角标
lazy var payIconView :UIImageView = {
let layerView = UIImageView()
layerView.image = UIImage(named: "home_player_pay")
layerView.frame = CGRect(x: 0, y: 0, width: 26, height: 15)
return layerView
}()
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 = .white
self.contentView.addSubview(self.iconImgView)
iconImgView.snp.makeConstraints { make in
make.left.top.equalTo(15)
make.width.equalTo(106)
make.height.equalTo(60)
}
self.iconImgView.addSubview(self.payIconView)
self.contentView.addSubview(self.titleLabel)
titleLabel.snp.makeConstraints { make in
make.left.equalTo(self.iconImgView.snp.right).offset(20)
make.top.equalTo(self.iconImgView.snp.top).offset(6)
make.right.equalToSuperview().offset(-10)
}
self.contentView.addSubview(self.subTitleLabel)
subTitleLabel.snp.makeConstraints { make in
make.left.equalTo(self.iconImgView.snp.right).offset(20)
make.top.equalTo(self.titleLabel.snp.bottom).offset(10)
make.right.equalToSuperview().offset(-10)
}
self.contentView.clipsToBounds = true
}
func setupNewUI(model:CNLiveVodPlayBlockListListModel){
self.titleLabel.text = model.title
self.subTitleLabel.text = model.subTitle
self.iconImgView.kf.setImage(with: URL(string: model.img))
if model.product?.check == true {
//免费或者付过费了
self.payIconView.isHidden = true
} else {
if model.product?.productType == "4" {
//这里表示可以进行试听
self.payIconView.isHidden = true
} else {
//需要付费
self.payIconView.isHidden = false
//分转元,没有小数点
let fenString = model.product!.iosRmb
// 将字符串转换为整数
// 使用guard语句确保字符串可以转换为整数
guard let fen = Int(fenString) else {
print("无法将字符串转换为整数")
return
}
// 计算元值(整数除法,自动舍去小数部分)
var yuan = fen / 100
if yuan <= 0{//如果是测试0.1元 ,线上默认设置为1元
yuan = 1
}
// 将结果转换为字符串
let yuanString = String(yuan)
}
}
if self.isJiShuSelected{
//选中
titleLabel.textColor = HexColor("#478BFF")
subTitleLabel.textColor = HexColor("#478BFF")
}else{
//未选中
titleLabel.textColor = HexColor("#333333")
subTitleLabel.textColor = HexColor("#999999")
}
}
}