109 lines
3.0 KiB
Swift
109 lines
3.0 KiB
Swift
//
|
|
// XSSearchHotListCardView.swift
|
|
// XSeri
|
|
//
|
|
// Created by 长沙鸿瑶 on 2026/2/2.
|
|
//
|
|
|
|
import UIKit
|
|
import SnapKit
|
|
|
|
final class XSSearchHotListCardView: UIView {
|
|
|
|
/// 榜单卡片数据
|
|
var section: XSSearchHotSection? {
|
|
didSet {
|
|
xs_applySection()
|
|
}
|
|
}
|
|
|
|
/// 点击榜单条目回调
|
|
var didSelectItem: ((_ model: XSShortModel) -> Void)?
|
|
|
|
private lazy var titleLabel: UILabel = {
|
|
let label = UILabel()
|
|
label.font = .font(ofSize: 14, weight: .bold)
|
|
return label
|
|
}()
|
|
|
|
private lazy var iconImageView: UIImageView = {
|
|
let imageView = UIImageView()
|
|
imageView.contentMode = .scaleAspectFit
|
|
return imageView
|
|
}()
|
|
|
|
private lazy var stackView: UIStackView = {
|
|
let view = UIStackView()
|
|
view.axis = .vertical
|
|
view.spacing = 8
|
|
return view
|
|
}()
|
|
|
|
override init(frame: CGRect) {
|
|
super.init(frame: frame)
|
|
xs_setupUI()
|
|
}
|
|
|
|
required init?(coder: NSCoder) {
|
|
fatalError("init(coder:) has not been implemented")
|
|
}
|
|
}
|
|
|
|
extension XSSearchHotListCardView {
|
|
|
|
private func xs_setupUI() {
|
|
layer.cornerRadius = 12
|
|
layer.masksToBounds = true
|
|
layer.borderWidth = 1
|
|
|
|
addSubview(titleLabel)
|
|
addSubview(iconImageView)
|
|
addSubview(stackView)
|
|
|
|
iconImageView.snp.makeConstraints { make in
|
|
make.left.equalToSuperview().offset(16)
|
|
make.top.equalToSuperview().offset(20)
|
|
}
|
|
|
|
titleLabel.snp.makeConstraints { make in
|
|
make.centerY.equalTo(iconImageView)
|
|
make.left.equalTo(iconImageView.snp.right).offset(2)
|
|
make.right.lessThanOrEqualToSuperview().offset(-10)
|
|
}
|
|
|
|
stackView.snp.makeConstraints { make in
|
|
make.left.equalToSuperview().offset(16)
|
|
make.right.equalToSuperview().offset(-16)
|
|
make.top.equalToSuperview().offset(53)
|
|
}
|
|
}
|
|
|
|
private func xs_applySection() {
|
|
guard let section = section else { return }
|
|
titleLabel.text = section.title
|
|
iconImageView.image = section.icon
|
|
|
|
switch section.style {
|
|
case .gold:
|
|
layer.borderColor = UIColor.FDE_7_B_8.withAlphaComponent(0.4).cgColor
|
|
titleLabel.textColor = .FDE_7_B_8
|
|
case .purple:
|
|
layer.borderColor = UIColor.E_0_C_6_FF.withAlphaComponent(0.2).cgColor
|
|
titleLabel.textColor = UIColor.E_0_C_6_FF.withAlphaComponent(0.7)
|
|
}
|
|
|
|
stackView.arrangedSubviews.forEach { $0.removeFromSuperview() }
|
|
section.items.enumerated().forEach { index, item in
|
|
let itemView = XSSearchHotListItemView()
|
|
itemView.configure(model: item, rank: index + 1, style: section.style)
|
|
itemView.didTap = { [weak self] model in
|
|
self?.didSelectItem?(model)
|
|
}
|
|
itemView.snp.makeConstraints { make in
|
|
make.height.equalTo(65)
|
|
}
|
|
stackView.addArrangedSubview(itemView)
|
|
}
|
|
}
|
|
}
|