Fableon/Fableon/Object/Class/Store/V/FAWalletHeaderView.swift
2025-11-04 16:46:56 +08:00

159 lines
5.2 KiB
Swift

//
// FAWalletHeaderView.swift
// Fableon
//
// Created by on 2025/10/22.
//
import UIKit
class FAWalletHeaderView: UIView {
var userInfo: FAUserInfo? {
didSet {
coinsView.setNeedsUpdateConfiguration()
bonusView.setNeedsUpdateConfiguration()
}
}
private lazy var contentView: UIView = {
let view = UIView()
view.backgroundColor = ._5_CA_8_FF_0_2
view.layer.cornerRadius = 12
view.layer.masksToBounds = true
return view
}()
private lazy var storeButton: UIButton = {
let button = FAGradientButton(type: .custom, primaryAction: UIAction(handler: { [weak self] _ in
guard let self = self else { return }
let vc = FAStoreViewController()
self.viewController?.navigationController?.pushViewController(vc, animated: true)
}))
button.layer.cornerRadius = 24
button.layer.masksToBounds = true
button.fa_colors = [UIColor.BEDFFF.cgColor, UIColor._52_A_2_F_1.cgColor]
button.fa_locations = [0, 1]
button.fa_startPoint = .init(x: 0, y: 0.5)
button.fa_endPoint = .init(x: 1, y: 0.5)
button.setTitle("fableon_store".localized, for: .normal)
button.setTitleColor(._000000, for: .normal)
button.titleLabel?.font = .font(ofSize: 18, weight: .bold)
return button
}()
private lazy var lineView: UIView = {
let view = UIView()
view.backgroundColor = .FFFFFF.withAlphaComponent(0.1)
return view
}()
private lazy var coinsView: UIButton = {
var config = UIButton.Configuration.plain()
config.image = UIImage(named: "coins_icon_02")
config.imagePadding = 11
config.attributedTitle = AttributedString("fableon_coins".localized, attributes: AttributeContainer([
.font : UIFont.font(ofSize: 10, weight: .bold),
.foregroundColor : UIColor.F_7_F_497
]))
let button = UIButton(configuration: config)
button.isUserInteractionEnabled = false
button.configurationUpdateHandler = { [weak self] button in
guard let self = self else { return }
button.configuration?.attributedSubtitle = AttributedString("\(self.userInfo?.coin_left_total ?? 0)", attributes: AttributeContainer([
.font : UIFont.font(ofSize: 14, weight: .bold),
.foregroundColor : UIColor.FFFFFF
]))
}
return button
}()
private lazy var bonusView: UIButton = {
var config = UIButton.Configuration.plain()
config.image = UIImage(named: "coins_icon_02")
config.imagePadding = 11
config.imagePlacement = .trailing
config.titleAlignment = .leading
config.attributedTitle = AttributedString("fableon_bonus".localized, attributes: AttributeContainer([
.font : UIFont.font(ofSize: 10, weight: .bold),
.foregroundColor : UIColor.F_7_F_497
]))
let button = UIButton(configuration: config)
button.isUserInteractionEnabled = false
button.configurationUpdateHandler = { [weak self] button in
guard let self = self else { return }
button.configuration?.attributedSubtitle = AttributedString("\(self.userInfo?.send_coin_left_total ?? 0)", attributes: AttributeContainer([
.font : UIFont.font(ofSize: 14, weight: .bold),
.foregroundColor : UIColor.FFFFFF
]))
}
return button
}()
override init(frame: CGRect) {
super.init(frame: frame)
fa_setupLayout()
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
extension FAWalletHeaderView {
private func fa_setupLayout() {
addSubview(contentView)
contentView.addSubview(storeButton)
contentView.addSubview(lineView)
contentView.addSubview(coinsView)
contentView.addSubview(bonusView)
contentView.snp.makeConstraints { make in
make.left.equalToSuperview().offset(16)
make.centerX.equalToSuperview()
make.top.equalToSuperview().offset(25)
make.height.equalTo(150)
}
storeButton.snp.makeConstraints { make in
make.left.equalToSuperview().offset(16)
make.centerX.equalToSuperview()
make.bottom.equalToSuperview().offset(-14)
make.height.equalTo(48)
}
lineView.snp.makeConstraints { make in
make.centerX.equalToSuperview()
make.top.equalToSuperview().offset(33)
make.width.equalTo(1)
make.height.equalTo(30)
}
coinsView.snp.makeConstraints { make in
make.left.equalToSuperview()
make.right.equalTo(lineView.snp.left)
make.centerY.equalTo(lineView)
}
bonusView.snp.makeConstraints { make in
make.left.equalTo(lineView.snp.right)
make.right.equalToSuperview()
make.centerY.equalTo(lineView)
}
}
}