BeeReel/BeeReel/Class/Home/View/Spotlight/BRSpotlightTopCell.swift
2025-07-01 14:33:21 +08:00

173 lines
5.2 KiB
Swift

//
// BRSpotlightTopCell.swift
// BeeReel
//
// Created by on 2025/6/30.
//
import UIKit
class BRSpotlightTopCell: BRCollectionViewCell {
var model: BRShortModel? {
didSet {
coverImageView.br_setImage(url: model?.image_url)
titleLabel.text = model?.name
categoryLabel.text = model?.category?.first
hotView.setNeedsUpdateConfiguration()
}
}
var num: Int = 0 {
didSet {
switch num {
case 1:
numView.image = UIImage(named: "number_icon_01")
numView.isHidden = false
case 2:
numView.image = UIImage(named: "number_icon_02")
numView.isHidden = false
case 3:
numView.image = UIImage(named: "number_icon_03")
numView.isHidden = false
default:
numView.isHidden = true
}
}
}
private lazy var coverImageView: BRImageView = {
let imageView = BRImageView()
return imageView
}()
private lazy var coverMarkView: UIImageView = {
let imageView = UIImageView(image: UIImage(named: "cover_mark_icon_01"))
return imageView
}()
private lazy var playImageView: UIImageView = {
let imageView = UIImageView(image: UIImage(named: "play_icon_03"))
return imageView
}()
private lazy var textBgView: UIImageView = {
let imageView = UIImageView(image: UIImage(named: "text_bg_image_01"))
return imageView
}()
private lazy var numView: UIImageView = {
let imageView = UIImageView()
return imageView
}()
private lazy var titleLabel: UILabel = {
let label = UILabel()
label.font = .fontMedium(ofSize: 12)
label.textColor = .color1C1C1C()
label.numberOfLines = 2
return label
}()
private lazy var categoryLabel: UILabel = {
let label = UILabel()
label.font = .fontRegular(ofSize: 10)
label.textColor = .color899D00()
return label
}()
private lazy var hotView: UIButton = {
var config = UIButton.Configuration.plain()
config.image = UIImage(named: "hot_icon_02")
config.imagePlacement = .leading
config.imagePadding = 2
config.contentInsets = .init(top: 0, leading: 0, bottom: 0, trailing: 0)
let button = UIButton(configuration: config)
button.isUserInteractionEnabled = false
button.configurationUpdateHandler = { [weak self] button in
guard let self = self else { return }
let count = model?.watch_total ?? 0
var string = "\(count)"
if count > 100 {
string = String(format: "%.1fk", Float(count) / 1000)
}
button.configuration?.attributedTitle = AttributedString.br_createAttributedString(string: string, color: .colorFF7489(), font: .fontRegular(ofSize: 10))
}
return button
}()
override init(frame: CGRect) {
super.init(frame: frame)
br_setupUI()
}
@MainActor required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
extension BRSpotlightTopCell {
private func br_setupUI() {
contentView.layer.cornerRadius = 11
contentView.layer.masksToBounds = true
contentView.addSubview(coverImageView)
coverImageView.addSubview(numView)
coverImageView.addSubview(coverMarkView)
contentView.addSubview(playImageView)
coverImageView.addSubview(textBgView)
textBgView.addSubview(titleLabel)
textBgView.addSubview(categoryLabel)
textBgView.addSubview(hotView)
coverImageView.snp.makeConstraints { make in
make.edges.equalToSuperview()
}
numView.snp.makeConstraints { make in
make.left.equalToSuperview().offset(10)
make.top.equalToSuperview().offset(10)
}
coverMarkView.snp.makeConstraints { make in
make.right.bottom.equalToSuperview()
}
playImageView.snp.makeConstraints { make in
make.right.equalToSuperview().offset(0)
make.bottom.equalToSuperview().offset(0)
}
textBgView.snp.makeConstraints { make in
make.left.equalToSuperview().offset(10)
make.right.equalToSuperview().offset(-10)
make.bottom.equalToSuperview().offset(-10)
}
titleLabel.snp.makeConstraints { make in
make.left.equalToSuperview().offset(8)
make.top.equalToSuperview().offset(7)
make.right.lessThanOrEqualToSuperview().offset(-8)
}
categoryLabel.snp.makeConstraints { make in
make.left.equalToSuperview().offset(8)
make.top.equalTo(titleLabel.snp.bottom).offset(5)
}
hotView.snp.makeConstraints { make in
make.left.equalToSuperview().offset(8)
make.bottom.equalToSuperview().offset(-10)
}
}
}