CNLiveRealHotListDetailCell.swift 3.54 KB
//
//  CNLiveRealHotListDetailCell.swift
//  metaCode
//
//  Created by zx on 2024/5/11.
//  实时热榜详情页列表cell

import Foundation
import Kingfisher

class CNLiveRealHotListDetailCell: UICollectionViewCell {
    
    //是前三
    var num = 0//第几
    
    //contentsModel
    var _contentsModel : CNLiveDownSlideContentsModel?
    var contentsModel : CNLiveDownSlideContentsModel? {
        get{
            _contentsModel
        }
        set{
            _contentsModel = newValue!
            setupNewUI(model: _contentsModel!)
        }
    }
    
    lazy var iconImgView :UIImageView = {
        let iconImgView = UIImageView(frame: CGRect(x: 15, y: 0, width: 95, height: 138))
        iconImgView.contentMode = .scaleAspectFill
        iconImgView.clipsToBounds = true
        return iconImgView
    }()
    
    lazy var titleLabel: UILabel = {
        let titleLabel = UILabel.init(frame: CGRectMake(self.iconImgView.right+15, self.iconImgView.top, KSreenWidth-(self.iconImgView.right+15)-15, 23))
        titleLabel.textColor = HexColor("#333333")
        titleLabel.textAlignment = .left
        titleLabel.font = BoldFont_16
        return titleLabel
    }()
    lazy var subTitleLabel: UILabel = {
        let titleLabel = UILabel.init(frame: CGRectMake(self.titleLabel.left, self.titleLabel.bottom+5, self.titleLabel.width, 50))
        titleLabel.textColor = HexColor("#999999")
        titleLabel.textAlignment = .left
        titleLabel.numberOfLines = 3
        titleLabel.font = BoldFont_12
        return titleLabel
    }()

    //第一第二第三角标
    lazy var firstIconView :UIImageView = {
        let layerView = UIImageView()
        layerView.frame = CGRect(x: 15+5, y: 0, width: 20, height: 17)
        return layerView
    }()
    lazy var numTitleLabel: UILabel = {
        let titleLabel = UILabel(frame: self.firstIconView.bounds)
        titleLabel.textAlignment = .center
        titleLabel.text = "1"
        titleLabel.font = Font_12
        return titleLabel
    }()

    
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.contentView.addSubview(self.iconImgView)
        self.contentView.addSubview(self.titleLabel)
        self.contentView.addSubview(self.subTitleLabel)
        self.contentView.addSubview(self.firstIconView)
        self.firstIconView.addSubview(self.numTitleLabel)
        self.firstIconView.isHidden = true
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func setupNewUI(model:CNLiveDownSlideContentsModel){
        self.iconImgView.kf.setImage(with: URL(string:model.poster))
        self.titleLabel.text = model.title
        self.subTitleLabel.text = model.subTitle
        if self.num == 1{
            self.firstIconView.isHidden = false
            self.firstIconView.backgroundColor = HexColor("#F23A87")
            self.numTitleLabel.text = "1"
//            self.firstIconView.image = UIImage(named: "")
        }else if self.num == 2{
            self.firstIconView.isHidden = false
            self.firstIconView.backgroundColor = HexColor("#FB723F")
            self.numTitleLabel.text = "2"
//            self.firstIconView.image = UIImage(named: "")
        }else if self.num == 3{
            self.firstIconView.isHidden = false
            self.firstIconView.backgroundColor = HexColor("#FFB03D")
            self.numTitleLabel.text = "3"
//            self.firstIconView.image = UIImage(named: "")
        }else{
            self.firstIconView.isHidden = true
            self.numTitleLabel.text = ""
        }
    }
}