116 lines
3.6 KiB
Swift
116 lines
3.6 KiB
Swift
//
|
|
// BRRewardCoinsRecordCell.swift
|
|
// BeeReel
|
|
//
|
|
// Created by 长沙鸿瑶 on 2025/7/28.
|
|
//
|
|
|
|
import UIKit
|
|
|
|
class BRRewardCoinsRecordCell: BRCollectionViewCell {
|
|
|
|
var model: BRRewardCoinRecordModel? {
|
|
didSet {
|
|
titleLabel.text = model?.type
|
|
timeLabel.text = model?.created_at
|
|
coinView.setNeedsUpdateConfiguration()
|
|
|
|
let expireDate = Date(timeIntervalSince1970: model?.expired_time ?? 0)
|
|
let nowDate = Date()
|
|
let days = nowDate.differenceDay(date: expireDate)
|
|
|
|
if days > 0 {
|
|
contentLabel.text = "Expires in ## days".localizedReplace(text: "\(days)")
|
|
} else {
|
|
contentLabel.text = "Expired".localized
|
|
}
|
|
}
|
|
}
|
|
|
|
private lazy var titleLabel: UILabel = {
|
|
let label = UILabel()
|
|
label.font = .fontRegular(ofSize: 14)
|
|
label.textColor = .color1C1C1C()
|
|
return label
|
|
}()
|
|
|
|
private lazy var contentLabel: UILabel = {
|
|
let label = UILabel()
|
|
label.font = .fontRegular(ofSize: 12)
|
|
label.textColor = .colorC2C2C2()
|
|
return label
|
|
}()
|
|
|
|
private lazy var timeLabel: UILabel = {
|
|
let label = UILabel()
|
|
label.font = .fontRegular(ofSize: 11)
|
|
label.textColor = .colorC2C2C2()
|
|
label.setContentHuggingPriority(.required, for: .horizontal)
|
|
label.setContentCompressionResistancePriority(.required, for: .horizontal)
|
|
return label
|
|
}()
|
|
|
|
private lazy var coinView: UIButton = {
|
|
var config = UIButton.Configuration.plain()
|
|
config.imagePadding = 2
|
|
config.image = UIImage(named: "Frame 6")
|
|
config.imagePlacement = .trailing
|
|
config.contentInsets = .zero
|
|
|
|
let button = UIButton(configuration: config)
|
|
button.isUserInteractionEnabled = false
|
|
button.configurationUpdateHandler = { [weak self] button in
|
|
guard let self = self else { return }
|
|
|
|
button.configuration?.attributedTitle = AttributedString.br_createAttributedString(string: "+\(self.model?.coins ?? 0)", color: .color7ECD5E(), font: .fontMedium(ofSize: 15))
|
|
}
|
|
return button
|
|
}()
|
|
|
|
override init(frame: CGRect) {
|
|
super.init(frame: frame)
|
|
self.contentView.backgroundColor = .colorFAFAFA()
|
|
self.contentView.layer.cornerRadius = 10
|
|
self.contentView.layer.masksToBounds = true
|
|
|
|
br_setupUI()
|
|
}
|
|
|
|
@MainActor required init?(coder: NSCoder) {
|
|
fatalError("init(coder:) has not been implemented")
|
|
}
|
|
}
|
|
|
|
extension BRRewardCoinsRecordCell {
|
|
|
|
private func br_setupUI() {
|
|
contentView.addSubview(titleLabel)
|
|
contentView.addSubview(contentLabel)
|
|
contentView.addSubview(timeLabel)
|
|
contentView.addSubview(coinView)
|
|
|
|
titleLabel.snp.makeConstraints { make in
|
|
make.left.equalToSuperview().offset(12)
|
|
make.top.equalToSuperview().offset(11)
|
|
}
|
|
|
|
contentLabel.snp.makeConstraints { make in
|
|
make.left.equalToSuperview().offset(12)
|
|
make.bottom.equalToSuperview().offset(-15)
|
|
make.right.equalTo(timeLabel.snp.left).offset(-25)
|
|
}
|
|
|
|
timeLabel.snp.makeConstraints { make in
|
|
make.centerY.equalTo(contentLabel)
|
|
make.right.equalToSuperview().offset(-10)
|
|
}
|
|
|
|
coinView.snp.makeConstraints { make in
|
|
make.centerY.equalTo(titleLabel)
|
|
make.right.equalToSuperview().offset(-11)
|
|
}
|
|
|
|
}
|
|
|
|
}
|