CNLiveDownSlideTodayRecommendCell.swift 2.34 KB
//
//  CNLiveDownSlideTodayRecommendCell.swift
//  metaCode
//
//  Created by zx on 2023/10/20.
//  type:74 今日推荐

import Foundation

///今日推荐高度
let DownSlideTodayRecommendH: CGFloat = 105
///今日推荐宽度
let DownSlideTodayRecommendW: CGFloat = KSreenWidth-DownSlideRecommendLeftGap*2

class CNLiveDownSlideTodayRecommendCell: UITableViewCell {
    //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
        contentView.backgroundColor = HexColor(kCNDownSlideBackgroundColorHex)
    }
    
    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(contentMdl: contentMdl!)
    }
}