// // StatisticsStatCardView.swift // suixinkan // import SnapKit import UIKit /// 数据统计指标卡,对齐 Android `StatCard`。 final class StatisticsStatCardView: UIView { private let titleLabel = UILabel() private let valueLabel = UILabel() private let iconView = UIImageView() init(title: String, valueColor: UIColor, backgroundColor: UIColor, iconName: String) { super.init(frame: .zero) titleLabel.text = title valueLabel.textColor = valueColor self.backgroundColor = backgroundColor iconView.image = UIImage(named: iconName) setupUI() } @available(*, unavailable) required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } func configure(value: String) { valueLabel.text = value } private func setupUI() { layer.cornerRadius = 12 clipsToBounds = true titleLabel.font = .systemFont(ofSize: 14) titleLabel.textColor = UIColor.black.withAlphaComponent(0.6) valueLabel.font = .systemFont(ofSize: 18, weight: .bold) valueLabel.numberOfLines = 1 valueLabel.adjustsFontSizeToFitWidth = true valueLabel.minimumScaleFactor = 0.8 iconView.contentMode = .scaleAspectFit addSubview(titleLabel) addSubview(valueLabel) addSubview(iconView) titleLabel.snp.makeConstraints { make in make.top.leading.equalToSuperview().inset(12) make.trailing.lessThanOrEqualTo(iconView.snp.leading).offset(-8) } valueLabel.snp.makeConstraints { make in make.top.equalTo(titleLabel.snp.bottom).offset(3) make.leading.bottom.equalToSuperview().inset(12) make.trailing.lessThanOrEqualTo(iconView.snp.leading).offset(-8) } iconView.snp.makeConstraints { make in make.trailing.equalToSuperview().inset(8) make.centerY.equalToSuperview() make.size.equalTo(48) } } }