Veloria/Veloria/Class/Wallet/View/VPCoinsBuyCell.swift
2025-06-12 18:24:39 +08:00

220 lines
6.6 KiB
Swift

//
// VPCoinsBuyCell.swift
// Veloria
//
// Created by on 2025/5/30.
//
import UIKit
class VPCoinsBuyCell: VPCollectionViewCell {
var item: VPPayTemplateItem? {
didSet {
coinCountLabel.text = "+\(item?.coins ?? 0)"
priceLabel.text = "\(item?.currency ?? "")\(item?.price ?? "0")"
if let mark = item?.corner_marker, !mark.isEmpty {
hotBgView.isHidden = false
hotLabel.text = mark
} else {
hotBgView.isHidden = true
}
if let sendCoins = item?.send_coins, sendCoins > 0, let coins = item?.coins {
sendBgView.isHidden = false
sendCountLabel.isHidden = false
sendCountLabel.text = "veloria_bonus_count_text".localizedReplace(text: "\(sendCoins)")
let percent = CGFloat(sendCoins) / CGFloat(coins) * 100
sendLabel.text = String(format: "+%.0f%%".localized, percent)
} else {
sendBgView.isHidden = true
sendCountLabel.isHidden = true
}
}
}
var vp_isSelected: Bool = false {
didSet {
if vp_isSelected {
self.bgView.isHidden = false
selectedImageView.isHidden = false
} else {
self.bgView.isHidden = true
selectedImageView.isHidden = true
}
}
}
private lazy var bgView: VPGradientView = {
let view = VPGradientView()
view.vp_setGradientBorder()
view.colors = [UIColor.color05CEA0(alpha: 0.3).cgColor, UIColor.color7C174F(alpha: 0.3).cgColor]
view.locations = [0, 1]
view.startPoint = .init(x: 0, y: 0.3)
view.endPoint = .init(x: 1, y: 0.8)
return view
}()
private lazy var selectedImageView: UIImageView = {
let imageView = UIImageView(image: UIImage(named: "selected_icon_01"))
return imageView
}()
private lazy var coinBgView: UIView = {
let view = UIView()
return view
}()
private lazy var coinCountLabel: UILabel = {
let label = UILabel()
label.font = .fontMedium(ofSize: 16)
label.textColor = .colorFFFFFF()
return label
}()
private lazy var iconImageView: UIImageView = {
let imageView = UIImageView(image: UIImage(named: "coin_icon_04"))
return imageView
}()
private lazy var sendCountLabel: UILabel = {
let label = UILabel()
label.font = .fontRegular(ofSize: 12)
label.textColor = .color05CEA0()
return label
}()
private lazy var priceLabel: UILabel = {
let label = UILabel()
label.font = .fontRegular(ofSize: 12)
label.textColor = .colorFFFFFF(alpha: 0.6)
return label
}()
private lazy var hotBgView: UIView = {
let view = UIView()
view.backgroundColor = .colorBE0069()
view.addRadius(topLeft: 8, topRight: 0, bottomLeft: 0, bottomRight: 8)
view.layer.zPosition = 0
return view
}()
private lazy var hotLabel: UILabel = {
let label = UILabel()
label.textColor = .colorFFFFFF()
label.font = .fontRegular(ofSize: 11)
return label
}()
private lazy var sendBgView: UIView = {
let view = UIView()
view.backgroundColor = .color05CEA0()
view.addRadius(topLeft: 0, topRight: 8, bottomLeft: 8, bottomRight: 0)
view.layer.zPosition = 0
return view
}()
private lazy var sendLabel: UILabel = {
let label = UILabel()
label.font = .fontRegular(ofSize: 11)
label.textColor = .color00211A()
return label
}()
override init(frame: CGRect) {
super.init(frame: frame)
bgView.layer.cornerRadius = 8
bgView.layer.masksToBounds = true
self.contentView.layer.cornerRadius = 8
self.contentView.layer.masksToBounds = true
self.contentView.layer.borderColor = UIColor.colorFFFFFF(alpha: 0.25).cgColor
self.contentView.layer.borderWidth = 1
vp_setupUI()
}
@MainActor required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
extension VPCoinsBuyCell {
private func vp_setupUI() {
contentView.addSubview(bgView)
contentView.addSubview(selectedImageView)
contentView.addSubview(coinBgView)
coinBgView.addSubview(coinCountLabel)
coinBgView.addSubview(iconImageView)
contentView.addSubview(sendCountLabel)
contentView.addSubview(priceLabel)
contentView.addSubview(hotBgView)
hotBgView.addSubview(hotLabel)
contentView.addSubview(sendBgView)
sendBgView.addSubview(sendLabel)
bgView.snp.makeConstraints { make in
make.edges.equalToSuperview()
}
selectedImageView.snp.makeConstraints { make in
make.bottom.right.equalToSuperview()
}
coinBgView.snp.makeConstraints { make in
make.centerX.equalToSuperview()
make.top.equalToSuperview().offset(28)
}
coinCountLabel.snp.makeConstraints { make in
make.left.equalToSuperview()
make.centerY.equalToSuperview()
}
sendCountLabel.snp.makeConstraints { make in
make.centerX.equalToSuperview()
make.top.equalTo(coinBgView.snp.bottom).offset(8)
}
iconImageView.snp.makeConstraints { make in
make.left.equalTo(coinCountLabel.snp.right).offset(3)
make.right.equalToSuperview()
make.centerY.equalToSuperview()
make.top.equalToSuperview()
}
priceLabel.snp.makeConstraints { make in
make.centerX.equalToSuperview()
make.bottom.equalToSuperview().offset(-11)
}
hotBgView.snp.makeConstraints { make in
make.left.top.equalToSuperview()
make.height.equalTo(16)
}
hotLabel.snp.makeConstraints { make in
make.center.equalToSuperview()
make.left.equalToSuperview().offset(5)
}
sendBgView.snp.makeConstraints { make in
make.right.top.equalToSuperview()
make.height.equalTo(16)
}
sendLabel.snp.makeConstraints { make in
make.center.equalToSuperview()
make.left.equalToSuperview().offset(5)
}
}
}