CNDownSlideSingleCourseCell.swift
11.2 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
//
// CNDownSlideSingleCourseCell.swift
// metaCode
//
// Created by zx on 2023/10/16.
// 单课程大图专辑 | 全部课程列表
import Foundation
import UIKit
enum GlobalConstants {
static let leftMargin: CGFloat = 20
static let toDayCardRowH: CGFloat = 440
static let toDayCardCornerRadius: CGFloat = 12.0
static let todayCardSize: CGSize = CGSize(width: KSreenWidth - 2 * 15, height: DownSlideSingleCourseImgH)
static let cardDetailTopImageH: CGFloat = 500
static let iconBorderColor: CGColor = UIColor(red: 239/255.0, green: 240/255.0, blue: 241/255.0, alpha: 1).cgColor
static let iconBorderWidth: CGFloat = 0.8
static let iconCornerRadius: CGFloat = 17.5
static let textBlueColor = UIColor(red: 0/255.0, green: 122/255.0, blue: 255/255.0, alpha: 1.0) //007AFF
static let speratorLineColor = UIColor(red: 224/255.0, green: 224/255.0, blue: 224/255.0, alpha: 1)
}
///全部课程 标题高度
let DownSlideAllCourseTitleH: CGFloat = 55
//全部课程 每row_topY间距
let DownSlideAllCourseRowTopYGap: CGFloat = 10
//全部课程 每row_topY间距
let DownSlideAllCourseRowBottomYGap: CGFloat = 20
//全部课程 每row_img宽高
let DownSlideAllCourseRowImageWH: CGFloat = 45
///全部课程 每row高度
let DownSlideAllCourseRowH: CGFloat = DownSlideAllCourseRowTopYGap+DownSlideAllCourseRowBottomYGap + DownSlideAllCourseRowImageWH
///全部课程 宽度
let DownSlideAllCourseW: CGFloat = KSreenWidth - DownSlideRecommendLeftGap*2
///单节课程 大图高度
let DownSlideSingleCourseImgH: CGFloat = 345
///单节课程 更多课程高度
let DownSlideSingleCourseMoreH: CGFloat = 60
///单节课程 宽度
let DownSlideSingleCourseW: CGFloat = KSreenWidth - DownSlideRecommendLeftGap*2
class CNDownSlideSingleCourseCell: UITableViewCell {
let bgBackView = UIView()
let bgImageView = UIImageView()
//slideModel
var _slideModel : CNLiveDownSlideModel?
var slideModel : CNLiveDownSlideModel? {
get{
_slideModel
}
set{
_slideModel = newValue!
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 = HexColor(kCNDownSlideBackgroundColorHex)
}
func setupNewUI(model:CNLiveDownSlideModel){
contentView.subviews.forEach { view in
view.removeFromSuperview()
}
bgBackView.subviews.forEach { view in
view.removeFromSuperview()
}
bgImageView.subviews.forEach { view in
view.removeFromSuperview()
}
if model.type == SlideModelTypeAllCourse12 {
//全部课程列表
contentView.addSubview(bgBackView)
bgBackView.frame = CGRect(x: DownSlideRecommendLeftGap, y: 0,width:DownSlideSingleCourseW , height:model.cellH-DownSlideRecommendLeftGap)
// 设置阴影效果
bgBackView.layer.masksToBounds = false
//定义view的阴影颜色
bgBackView.layer.shadowColor = UIColor(red: 0, green: 0, blue: 0, alpha: 0.1).cgColor
//定义view的阴影透明度,注意:如果view没有设置背景色阴影也是不会显示的
bgBackView.layer.shadowOpacity = 1
//定义view的阴影宽度,模糊计算的半径
bgBackView.layer.shadowRadius = 10.0
//阴影偏移量
bgBackView.layer.shadowOffset = CGSize(width: 0, height: 0)
bgBackView.layer.cornerRadius = 12
bgBackView.backgroundColor = .white
var titleTop:CGFloat = DownSlideRecommendLeftGap
if model.blockSubTitle?.count ?? 0 > 0{
let subtitleLbl = UILabel(frame: CGRect(x: DownSlideRecommendLeftGap, y: DownSlideRecommendLeftGap, width: DownSlideSingleCourseW-DownSlideRecommendLeftGap*2, height: 17))
subtitleLbl.text = model.blockSubTitle
subtitleLbl.font = Font_12
subtitleLbl.textColor = HexColor("#999999")
bgBackView.addSubview(subtitleLbl)
titleTop = DownSlideRecommendLeftGap+17+1
}
let titleLbl = UILabel(frame: CGRect(x: DownSlideRecommendLeftGap, y: titleTop, width: DownSlideSingleCourseW-DownSlideRecommendLeftGap*2, height: 30))
titleLbl.text = model.blockName ?? "全部课程"
titleLbl.font = BoldFont_21
titleLbl.textColor = HexColor("#333333")
bgBackView.addSubview(titleLbl)
//总块数
let contentsNum = model.contents.count
//model行数
let row = model.rowNum
//总显示块数
var totalNum = (contentsNum >= row) ? row : contentsNum
if row == 0{//row为0 , contents全部显示
totalNum = contentsNum
}
for i in 0..<totalNum{//i是第几行
let contentMdl = model.contents[i]
//小icon
let imageView = UIImageView(frame: CGRectMake(DownSlideRecommendLeftGap, titleLbl.bottom+DownSlideRecommendLeftGap+CGFloat(i)*(DownSlideAllCourseRowTopYGap+DownSlideAllCourseRowImageWH+DownSlideAllCourseRowBottomYGap), CGFloat(DownSlideAllCourseRowImageWH), CGFloat(DownSlideAllCourseRowImageWH)))
imageView.kf.setImage(with: URL(string:contentMdl.poster ?? ""))
imageView.layer.cornerRadius = 12
imageView.clipsToBounds = true
imageView.contentMode = .scaleAspectFill
bgBackView.addSubview(imageView)
let titleLbl = UILabel(frame: CGRect(x: imageView.right+DownSlideRecommendLeftGap, y: imageView.top, width: DownSlideSingleCourseW-90-imageView.right, height: 21))
titleLbl.text = contentMdl.title ?? ""
titleLbl.font = Font_15
titleLbl.textColor = HexColor("#333333")
bgBackView.addSubview(titleLbl)
let subTitleLbl = UILabel(frame: CGRect(x: titleLbl.left, y:titleLbl.bottom+3 , width: titleLbl.width, height: 17))
subTitleLbl.text = contentMdl.subTitle ?? ""
subTitleLbl.font = Font_12
subTitleLbl.textColor = HexColor("#999999")
bgBackView.addSubview(subTitleLbl)
let enterBtn = UIButton(type: .custom)
enterBtn.frame = CGRect(x: bgBackView.right-25-65, y: 0, width: 65, height: 30)
enterBtn.centerY = imageView.centerY
enterBtn.setBackgroundImage(UIImage(named: "homepage_down_enter"), for: .normal)
enterBtn.setTitle("进入", for: .normal)
enterBtn.titleLabel?.font = BoldFont_13
enterBtn.setTitleColor(HexColor("#FFFFFF"), for: .normal)
enterBtn.addTarget(self, action: #selector(enterBtnAction(_:)), for: .touchUpInside)
enterBtn.tag = i
bgBackView.addSubview(enterBtn)
}
}else if model.type == SlideModelTypeOneCourse75 {
//单图课程
contentView.addSubview(bgBackView)
bgBackView.addSubview(bgImageView)
bgBackView.frame = CGRect(x: DownSlideRecommendLeftGap, y: 0,width:DownSlideSingleCourseW , height:DownSlideSingleCourseMoreH+DownSlideSingleCourseImgH)
// 设置阴影效果
bgBackView.layer.masksToBounds = false
//定义view的阴影颜色
bgBackView.layer.shadowColor = UIColor(red: 0, green: 0, blue: 0, alpha: 0.1).cgColor
//定义view的阴影透明度,注意:如果view没有设置背景色阴影也是不会显示的
bgBackView.layer.shadowOpacity = 1
//定义view的阴影宽度,模糊计算的半径
bgBackView.layer.shadowRadius = 10.0
//阴影偏移量
bgBackView.layer.shadowOffset = CGSize(width: 0, height: 0)
bgBackView.layer.cornerRadius = 12
bgBackView.backgroundColor = .white
bgImageView.frame = CGRect(x: 0, y: 0,width:DownSlideSingleCourseW , height:DownSlideSingleCourseImgH)
bgImageView.contentMode = .scaleAspectFill
bgImageView.layer.cornerRadius = GlobalConstants.toDayCardCornerRadius
bgImageView.layer.maskedCorners = [.layerMinXMinYCorner, .layerMaxXMinYCorner]
bgImageView.layer.masksToBounds = true
if let bgImgStr = model.background{
bgImageView.kf.setImage(with: URL(string: bgImgStr))
}else{
bgImageView.kf.setImage(with: URL(string: model.contents[0].poster ?? ""))
}
let titleLbl = UILabel(frame: CGRect(x: DownSlideRecommendLeftGap, y: DownSlideRecommendLeftGap, width: DownSlideSingleCourseW-DownSlideRecommendLeftGap*2, height: 30))
titleLbl.text = model.contents[0].title ?? ""
titleLbl.font = BoldFont_21
titleLbl.textColor = HexColor("#FFFFFF")
// bgImageView.addSubview(titleLbl)
let subTitleLbl = UILabel(frame: CGRect(x: DownSlideRecommendLeftGap, y:titleLbl.bottom , width: DownSlideSingleCourseW-DownSlideRecommendLeftGap*2, height: 30))
subTitleLbl.text = model.contents[0].subTitle ?? ""
subTitleLbl.font = Font_12
subTitleLbl.textColor = HexColor("#FFFFFF")
// bgImageView.addSubview(subTitleLbl)
//单节底部视图
let singleCourseBottomView = UIView(frame: CGRect(x: 0, y: DownSlideSingleCourseImgH, width: DownSlideSingleCourseW, height: DownSlideSingleCourseMoreH))
singleCourseBottomView.layer.cornerRadius = 12
singleCourseBottomView.layer.maskedCorners = [.layerMinXMaxYCorner, .layerMaxXMaxYCorner]
singleCourseBottomView.backgroundColor = .white
singleCourseBottomView.isUserInteractionEnabled = true
bgBackView.addSubview(singleCourseBottomView)
let moreLabel = UILabel(frame: CGRect(x: DownSlideRecommendLeftGap, y: 15, width: DownSlideSingleCourseW - 50 - DownSlideRecommendLeftGap , height: 30))
moreLabel.text = model.blockName ?? "更多"
moreLabel.font = BoldFont_15_Fit
moreLabel.textColor = HexColor("#333333")
singleCourseBottomView.addSubview(moreLabel)
let moreImgView = UIImageView(image: UIImage(named: "homepage_down_more"))
moreImgView.left = moreLabel.right
moreImgView.centerY = moreLabel.centerY
singleCourseBottomView.addSubview(moreImgView)
}
}
//MARK: - 事件
@objc func enterBtnAction(_ sender: UIButton){
let tag = sender.tag
let contentMdl = self.slideModel?.contents[tag]
CNLiveDownSlideTool.pushWebVCWithContentsMdl(contentMdl: contentMdl!)
}
}