68 lines
2.0 KiB
Swift
68 lines
2.0 KiB
Swift
//
|
|
// 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 = AppRadius.lg
|
|
clipsToBounds = true
|
|
|
|
titleLabel.font = .app(.body)
|
|
titleLabel.textColor = AppColor.textPrimary.withAlphaComponent(0.6)
|
|
|
|
valueLabel.font = .app(.metric)
|
|
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(AppSpacing.sm)
|
|
make.trailing.lessThanOrEqualTo(iconView.snp.leading).offset(-AppSpacing.xs)
|
|
}
|
|
valueLabel.snp.makeConstraints { make in
|
|
make.top.equalTo(titleLabel.snp.bottom).offset(3)
|
|
make.leading.bottom.equalToSuperview().inset(AppSpacing.sm)
|
|
make.trailing.lessThanOrEqualTo(iconView.snp.leading).offset(-AppSpacing.xs)
|
|
}
|
|
iconView.snp.makeConstraints { make in
|
|
make.trailing.equalToSuperview().inset(AppSpacing.xs)
|
|
make.centerY.equalToSuperview()
|
|
make.size.equalTo(48)
|
|
}
|
|
}
|
|
}
|