// // SPCoinRechargeCell.swift // MoviaBox // // Created by 佳尔 on 2025/4/28. // import UIKit class SPCoinRechargeCell: SPCollectionViewCell { var sp_isSelected = false var model: SPPayTemplateItem? { didSet { coinLabel.text = "\(model?.coins ?? 0)" if let mark = model?.corner_marker, !mark.isEmpty { hotView.isHidden = false } else { hotView.isHidden = true } if let sendCoins = model?.send_coins, sendCoins > 0, let coins = model?.coins { bonusLabel.isHidden = false ratioBgView.isHidden = false let ratio = String(format: "%.0f", CGFloat(sendCoins) / CGFloat(coins) * 100) ratioLabel.text = "+\(ratio)%" bonusLabel.text = "+\(sendCoins)" // bonusLabel.text = String(format: "movia_bonus_#".localized, "+\(sendCoins)") } else { bonusLabel.isHidden = true ratioBgView.isHidden = true } moneyLabel.text = "\(model?.currency ?? "")\(model?.price ?? "0")" } } //MARK: UI属性 private(set) lazy var containerView: UIImageView = { let imageView = UIImageView() return imageView }() private(set) lazy var coinBgView: UIView = { let view = UIView() return view }() private(set) lazy var coinIconImageView: UIImageView = { let imageView = UIImageView() return imageView }() private(set) lazy var coinLabel: UILabel = { let label = UILabel() label.textColor = .colorFFFFFF() return label }() private(set) lazy var bonusLabel: UILabel = { let label = UILabel() label.font = .fontMedium(ofSize: 14) label.textColor = .colorEF7301() return label }() private(set) lazy var moneyBgView: SPGradientView = { let view = SPGradientView() view.locations = [0, 0.5, 1] view.startPoint = .init(x: 0, y: 0.5) view.endPoint = .init(x: 1, y: 0.5) view.layer.masksToBounds = true return view }() private(set) lazy var moneyLabel: UILabel = { let label = UILabel() label.font = .fontMedium(ofSize: 14) return label }() private(set) lazy var ratioBgView: UIImageView = { let view = UIImageView() return view }() private(set) lazy var ratioLabel: UILabel = { let label = UILabel() return label }() private lazy var hotView: UIImageView = { let view = UIImageView(image: UIImage(named: "hot_icon_03")) return view }() override init(frame: CGRect) { super.init(frame: frame) contentView.layer.masksToBounds = false self.layer.masksToBounds = false _setupUI() } @MainActor required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } } extension SPCoinRechargeCell { private func _setupUI() { contentView.addSubview(containerView) contentView.addSubview(hotView) containerView.addSubview(coinBgView) coinBgView.addSubview(coinIconImageView) coinBgView.addSubview(coinLabel) containerView.addSubview(bonusLabel) containerView.addSubview(moneyBgView) moneyBgView.addSubview(moneyLabel) containerView.addSubview(ratioBgView) ratioBgView.addSubview(ratioLabel) containerView.snp.makeConstraints { make in make.edges.equalToSuperview() } hotView.snp.makeConstraints { make in make.left.equalToSuperview().offset(4) make.top.equalToSuperview().offset(-2) } coinBgView.snp.makeConstraints { make in make.centerX.equalToSuperview() make.top.equalToSuperview().offset(24) make.height.equalTo(25) } coinIconImageView.snp.makeConstraints { make in make.centerY.equalToSuperview() make.left.equalToSuperview() } coinLabel.snp.makeConstraints { make in make.centerY.equalToSuperview() make.left.equalTo(coinIconImageView.snp.right).offset(4) make.right.equalToSuperview() } bonusLabel.snp.makeConstraints { make in make.centerX.equalToSuperview() make.top.equalTo(coinBgView.snp.bottom).offset(8) } moneyLabel.snp.makeConstraints { make in make.center.equalToSuperview() } ratioBgView.snp.makeConstraints { make in make.top.right.equalToSuperview() } ratioLabel.snp.makeConstraints { make in make.centerY.equalToSuperview() make.left.equalToSuperview().offset(5) make.right.equalToSuperview().offset(-5) } } }