276 lines
9.2 KiB
Swift
276 lines
9.2 KiB
Swift
//
|
|
// XSCoinsPackHeaderView.swift
|
|
// XSeri
|
|
//
|
|
// Created by 长沙鸿瑶 on 2026/3/20.
|
|
//
|
|
|
|
import UIKit
|
|
import SnapKit
|
|
|
|
class XSCoinsPackHeaderView: UIView {
|
|
|
|
var model: XSCoinsPackModel? {
|
|
didSet {
|
|
coinsView1.coins = model?.week_max_total
|
|
coinsView2.coins = model?.week_total
|
|
|
|
|
|
let activeRefillsStr = NSMutableAttributedString(string: "Active Refills:".localized + " ")
|
|
activeRefillsStr.yy_font = .font(ofSize: 12, weight: .regular)
|
|
activeRefillsStr.yy_color = .white.withAlphaComponent(0.5)
|
|
|
|
let activeRefillsCount = NSMutableAttributedString(string: "\(model?.receive_count ?? 0)")
|
|
activeRefillsCount.yy_font = .font(ofSize: 12, weight: .medium)
|
|
activeRefillsCount.yy_color = .white
|
|
activeRefillsStr.append(activeRefillsCount)
|
|
activeRefillsLabel.attributedText = activeRefillsStr
|
|
|
|
if let coin = model?.receive_coins, coin > 0 {
|
|
claimButton.isEnabled = true
|
|
} else {
|
|
claimButton.isEnabled = false
|
|
}
|
|
|
|
claimButton.setNeedsUpdateConfiguration()
|
|
}
|
|
}
|
|
|
|
private lazy var titleLabel: UILabel = {
|
|
let label = UILabel()
|
|
label.font = .font(ofSize: 14, weight: .bold).withBoldItalic()
|
|
label.textColor = .FFDAA_4
|
|
label.text = "Rewards Overview".localized
|
|
return label
|
|
}()
|
|
|
|
private lazy var titleLineView: UIView = {
|
|
let view = UIImageView(image: UIImage(named: "coins_pack_line_image"))
|
|
return view
|
|
}()
|
|
|
|
private lazy var coinsView1: CoinsView = {
|
|
let view = CoinsView()
|
|
view.title = "Weekly Total".localized
|
|
view.coins = 0
|
|
return view
|
|
}()
|
|
|
|
private lazy var coinsView2: CoinsView = {
|
|
let view = CoinsView()
|
|
view.title = "Claimable Coins".localized
|
|
view.coins = 0
|
|
return view
|
|
}()
|
|
|
|
private lazy var coinsLineView: UIView = {
|
|
let view = UIImageView(image: UIImage(named: "line_image_01"))
|
|
return view
|
|
}()
|
|
|
|
private lazy var activeRefillsLabel: UILabel = {
|
|
let label = UILabel()
|
|
return label
|
|
}()
|
|
|
|
private lazy var claimButton: UIButton = {
|
|
var config = UIButton.Configuration.plain()
|
|
config.background.customView = self.buttonBgView
|
|
config.background.cornerRadius = 24
|
|
|
|
let button = UIButton(configuration: config, primaryAction: UIAction(handler: { [weak self] _ in
|
|
// self?.clickClaimButton?()
|
|
self?.claimButton.isEnabled = false
|
|
}))
|
|
button.isEnabled = false
|
|
button.configurationUpdateHandler = { [weak self] button in
|
|
guard let self = self else { return }
|
|
if button.isEnabled {
|
|
self.buttonBgView.xs_colors = [UIColor.F_5_BD_7_E.cgColor, UIColor.FFEABC.cgColor, UIColor.FFCF_99.cgColor]
|
|
|
|
let coinImage = UIImage(named: "coins_icon_01")!
|
|
let coinText = NSTextAttachment(image: coinImage)
|
|
coinText.bounds = .init(x: 0, y: -2.5, width: coinImage.size.width, height: coinImage.size.height)
|
|
let coinAtt = AttributedString(NSAttributedString(attachment: coinText))
|
|
|
|
let textAtt = AttributedString("Claim All".localized + " ", attributes: AttributeContainer([
|
|
.font : UIFont.font(ofSize: 14, weight: .bold),
|
|
.foregroundColor : UIColor._763200
|
|
]))
|
|
|
|
// let countAtt = AttributedString(" \(self.model?.receive_coins ?? 0)".localized, attributes: AttributeContainer([
|
|
// .font : UIFont.font(ofSize: 14, weight: .bold),
|
|
// .foregroundColor : UIColor.FFFFFF
|
|
// ]))
|
|
let countAtt = AttributedString(" 10".localized, attributes: AttributeContainer([
|
|
.font : UIFont.font(ofSize: 14, weight: .bold),
|
|
.foregroundColor : UIColor.FF_7700
|
|
]))
|
|
|
|
button.configuration?.attributedTitle = textAtt + coinAtt + countAtt
|
|
|
|
|
|
} else {
|
|
self.buttonBgView.xs_colors = [UIColor._616161.cgColor, UIColor._616161.cgColor, UIColor._616161.cgColor]
|
|
|
|
button.configuration?.attributedTitle = AttributedString("Get a Refill to Claim".localized, attributes: AttributeContainer([
|
|
.font : UIFont.font(ofSize: 14, weight: .bold),
|
|
.foregroundColor : UIColor.white.withAlphaComponent(0.5)
|
|
]))
|
|
}
|
|
|
|
}
|
|
return button
|
|
}()
|
|
|
|
private lazy var buttonBgView: XSView = {
|
|
let view = XSView()
|
|
view.xs_startPoint = .init(x: 0, y: 0.5)
|
|
view.xs_endPoint = .init(x: 1, y: 0.5)
|
|
return view
|
|
}()
|
|
|
|
private lazy var lineView: UIView = {
|
|
let view = UIImageView(image: UIImage(named: "line_image_02"))
|
|
return view
|
|
}()
|
|
|
|
override init(frame: CGRect) {
|
|
super.init(frame: frame)
|
|
|
|
xs_setupUI()
|
|
}
|
|
|
|
required init?(coder: NSCoder) {
|
|
fatalError("init(coder:) has not been implemented")
|
|
}
|
|
|
|
}
|
|
|
|
extension XSCoinsPackHeaderView {
|
|
|
|
private func xs_setupUI() {
|
|
addSubview(titleLabel)
|
|
addSubview(titleLineView)
|
|
addSubview(coinsLineView)
|
|
addSubview(coinsView1)
|
|
addSubview(coinsView2)
|
|
addSubview(activeRefillsLabel)
|
|
addSubview(claimButton)
|
|
addSubview(lineView)
|
|
|
|
titleLabel.snp.makeConstraints { make in
|
|
make.centerX.equalToSuperview()
|
|
make.top.equalToSuperview()
|
|
}
|
|
|
|
titleLineView.snp.makeConstraints { make in
|
|
make.left.right.equalToSuperview().inset(28)
|
|
make.top.equalTo(titleLabel.snp.bottom).offset(6)
|
|
}
|
|
|
|
coinsLineView.snp.makeConstraints { make in
|
|
make.centerX.equalToSuperview()
|
|
make.top.equalTo(titleLineView.snp.bottom).offset(27)
|
|
}
|
|
|
|
coinsView1.snp.makeConstraints { make in
|
|
make.centerY.equalTo(coinsLineView)
|
|
make.right.equalTo(coinsLineView.snp.left).offset(-18)
|
|
}
|
|
|
|
coinsView2.snp.makeConstraints { make in
|
|
make.centerY.equalTo(coinsLineView)
|
|
make.left.equalTo(coinsLineView.snp.right).offset(18)
|
|
}
|
|
|
|
activeRefillsLabel.snp.makeConstraints { make in
|
|
make.centerX.equalToSuperview()
|
|
make.top.equalTo(coinsLineView.snp.bottom).offset(25)
|
|
}
|
|
|
|
claimButton.snp.makeConstraints { make in
|
|
make.left.equalToSuperview().offset(28)
|
|
make.centerX.equalToSuperview()
|
|
make.top.equalTo(activeRefillsLabel.snp.bottom).offset(12)
|
|
make.height.equalTo(48)
|
|
}
|
|
|
|
lineView.snp.makeConstraints { make in
|
|
make.left.right.equalToSuperview().inset(28)
|
|
make.top.equalTo(claimButton.snp.bottom).offset(16)
|
|
make.bottom.equalToSuperview()
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
|
|
extension XSCoinsPackHeaderView {
|
|
|
|
class CoinsView: UIView {
|
|
|
|
var title: String? {
|
|
didSet {
|
|
titleLabel.text = title
|
|
}
|
|
}
|
|
|
|
var coins: Int? {
|
|
didSet {
|
|
coinsLabel.text = "\(coins ?? 0)"
|
|
}
|
|
}
|
|
|
|
private lazy var titleLabel: UILabel = {
|
|
let label = UILabel()
|
|
label.font = .font(ofSize: 12, weight: .bold)
|
|
label.textColor = .white.withAlphaComponent(0.5)
|
|
return label
|
|
}()
|
|
|
|
private lazy var coinsIconImageView: UIImageView = {
|
|
let imageView = UIImageView(image: UIImage(named: "coins_icon_06"))
|
|
return imageView
|
|
}()
|
|
|
|
private lazy var coinsLabel: UILabel = {
|
|
let label = UILabel()
|
|
label.font = .font(ofSize: 18, weight: .bold)
|
|
label.textColor = .FFDAA_4
|
|
return label
|
|
}()
|
|
|
|
override init(frame: CGRect) {
|
|
super.init(frame: frame)
|
|
|
|
addSubview(titleLabel)
|
|
addSubview(coinsIconImageView)
|
|
addSubview(coinsLabel)
|
|
|
|
titleLabel.snp.makeConstraints { make in
|
|
make.left.equalToSuperview()
|
|
make.top.equalToSuperview()
|
|
make.right.lessThanOrEqualToSuperview()
|
|
}
|
|
|
|
coinsIconImageView.snp.makeConstraints { make in
|
|
make.left.bottom.equalToSuperview()
|
|
make.top.equalTo(titleLabel.snp.bottom).offset(4)
|
|
}
|
|
|
|
coinsLabel.snp.makeConstraints { make in
|
|
make.left.equalTo(coinsIconImageView.snp.right).offset(4)
|
|
make.centerY.equalTo(coinsIconImageView)
|
|
make.right.lessThanOrEqualToSuperview()
|
|
}
|
|
}
|
|
|
|
required init?(coder: NSCoder) {
|
|
fatalError("init(coder:) has not been implemented")
|
|
}
|
|
|
|
}
|
|
|
|
}
|