CNLiveDownSlideTodayRecommendCell.swift
2.81 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
//
// CNLiveDownSlideTodayRecommendCell.swift
// metaCode
//
// Created by zx on 2023/10/20.
// type:74 今日推荐
import Foundation
///今日推荐高度
let DownSlideTodayRecommendH: CGFloat = DownSlideTodayRecommendW*105/345
///今日推荐宽度
let DownSlideTodayRecommendW: CGFloat = KSreenWidth-DownSlideRecommendLeftGap*2
class CNLiveDownSlideTodayRecommendCell: UITableViewCell {
//slideModel
var _slideModel : CNLiveDownSlideModel?
var slideModel : CNLiveDownSlideModel? {
get{
_slideModel
}
set{
_slideModel = newValue!
for obj in contentView.subviews{
obj.removeFromSuperview()
}
self.setupNewUI(model: _slideModel!)
}
}
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
self.selectionStyle = .none
contentView.backgroundColor = HexColor(kCNDownSlideBackgroundColorHex)
contentView.clipsToBounds = true
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
func setupNewUI(model:CNLiveDownSlideModel){
//总块数
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]
let imageView = UIImageView(frame: CGRectMake(DownSlideRecommendLeftGap, CGFloat(i)*(DownSlideTodayRecommendH+DownSlideRecommendLeftGap), CGFloat(DownSlideTodayRecommendW), CGFloat(DownSlideTodayRecommendH)))
imageView.kf.setImage(with: URL(string:contentMdl.poster ?? ""))
imageView.tag = i
imageView.layer.cornerRadius = 12
imageView.clipsToBounds = true
imageView.isUserInteractionEnabled = true
imageView.addGestureRecognizer(UITapGestureRecognizer.init(target: self, action: #selector(pushWebAction)))
contentView.addSubview(imageView)
}
}
@objc func pushWebAction(ges: UITapGestureRecognizer){
let imageView = ges.view as! UIImageView
let i = imageView.tag
let contentMdl = self.slideModel?.contents[i]
CNLiveDownSlideTool.pushWebVCWithContentsMdl(model: contentMdl?.model ?? "", contentId: contentMdl?.contentId ?? "", pid: contentMdl?.pid ?? "", shareUrl: contentMdl?.shareUrl ?? "", thirdUrl: contentMdl?.thirdUrl ?? "", title: contentMdl?.title ?? "", s_to: contentMdl?.s_to ?? "",trailerId: contentMdl?.trailerId ?? "", controller: nil, slideModel: nil)
}
}