Fableon/Fableon/Object/Class/Me/V/FAMeTableViewHeaderView.swift
湖北秦九 008d5b55b8 1
2025-11-21 09:12:46 +08:00

166 lines
5.7 KiB
Swift

//
// FAMeTableViewHeaderView.swift
// Fableon
//
// Created by on 2025/10/22.
//
import UIKit
class FAMeTableViewHeaderView: UIView {
var userInfo: FAUserInfo? {
didSet {
subtitleLabel.text = "vip_tip_01".localized
if userInfo?.is_vip == true {
subscribeView.isHidden = true
expirationView.isHidden = false
vipImageView.image = UIImage(named: "vip_image_02")
titleLabel.text = "fableon_activated".localized
} else {
subscribeView.isHidden = false
expirationView.isHidden = true
vipImageView.image = UIImage(named: "vip_image_01")
titleLabel.text = "fableon_not_activated".localized
// subtitleLabel.text = "vip_tip_02".localized
}
expirationView.setNeedsUpdateConfiguration()
}
}
private lazy var contentView: FAGradientView = {
let view = FAGradientView()
view.fa_colors = [UIColor.C_3_FAFF.cgColor, UIColor._7_FDBF_5.cgColor, UIColor._105_C_91.cgColor]
view.fa_locations = [0, 0.5, 1]
view.fa_startPoint = .init(x: 0, y: 0.5)
view.fa_endPoint = .init(x: 1, y: 0.5)
view.fa_setRoundedCorner(topLeft: 28, topRight: 6, bottomLeft: 6, bottomRight: 6)
return view
}()
private lazy var vipImageView: UIImageView = {
let imageView = UIImageView(image: UIImage(named: "vip_image_01"))
return imageView
}()
private lazy var titleLabel: UILabel = {
let label = UILabel()
label.font = .font(ofSize: 18, weight: .bold)
label.textColor = ._3_A_271_E
return label
}()
private lazy var subtitleLabel: UILabel = {
let label = UILabel()
label.font = .font(ofSize: 12, weight: .regular)
label.textColor = ._000000.withAlphaComponent(0.5)
return label
}()
private lazy var subscribeView: UIButton = {
var config = UIButton.Configuration.plain()
config.attributedTitle = AttributedString("fableon_subscribe".localized, attributes: AttributeContainer([
.font : UIFont.font(ofSize: 14, weight: .bold),
.foregroundColor : UIColor._333333
]))
let button = FAGradientButton(configuration: config)
button.isUserInteractionEnabled = false
button.layer.cornerRadius = 18
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)
return button
}()
private lazy var expirationView: UIButton = {
var config = UIButton.Configuration.plain()
config.contentInsets = .zero
config.image = UIImage(named: "Frame 3021")
config.imagePadding = 4
let button = UIButton(configuration: config)
button.isUserInteractionEnabled = false
button.configurationUpdateHandler = { [weak self] button in
guard let self = self else { return }
let date = Date(timeIntervalSince1970: userInfo?.vip_end_time ?? 0)
let text = "vip_expires_date".localizedReplace(text: date.fa_formatString("yyyy-MM-dd"))
button.configuration?.attributedTitle = AttributedString(text, attributes: AttributeContainer([
.font : UIFont.font(ofSize: 12, weight: .medium),
.foregroundColor : UIColor._3_A_271_E
]))
}
return button
}()
override init(frame: CGRect) {
super.init(frame: frame)
let tap = UITapGestureRecognizer { [weak self] _ in
guard let self = self else { return }
let vc = FAStoreViewController()
self.viewController?.navigationController?.pushViewController(vc, animated: true)
}
contentView.addGestureRecognizer(tap)
fa_setupLayout()
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
extension FAMeTableViewHeaderView {
private func fa_setupLayout() {
addSubview(contentView)
contentView.addSubview(vipImageView)
contentView.addSubview(titleLabel)
contentView.addSubview(subtitleLabel)
contentView.addSubview(subscribeView)
contentView.addSubview(expirationView)
contentView.snp.makeConstraints { make in
make.left.equalToSuperview().offset(16)
make.centerX.equalToSuperview()
make.top.bottom.equalToSuperview()
}
vipImageView.snp.makeConstraints { make in
make.centerY.equalToSuperview()
make.right.equalToSuperview().offset(-4)
}
titleLabel.snp.makeConstraints { make in
make.left.equalToSuperview().offset(16)
make.top.equalToSuperview().offset(16)
}
subtitleLabel.snp.makeConstraints { make in
make.left.equalToSuperview().offset(16)
make.top.equalTo(titleLabel.snp.bottom).offset(3)
}
subscribeView.snp.makeConstraints { make in
make.left.equalToSuperview().offset(16)
make.bottom.equalToSuperview().offset(-16)
make.height.equalTo(36)
make.width.equalTo(130)
}
expirationView.snp.makeConstraints { make in
make.left.equalToSuperview().offset(16)
make.bottom.equalToSuperview().offset(-16)
}
}
}