实现我的 Tab、对齐 Android 流程并接入 OSS 上传
This commit is contained in:
135
suixinkan/UI/Profile/ProfileInfoRowView.swift
Normal file
135
suixinkan/UI/Profile/ProfileInfoRowView.swift
Normal file
@ -0,0 +1,135 @@
|
||||
//
|
||||
// ProfileInfoRowView.swift
|
||||
// suixinkan
|
||||
//
|
||||
|
||||
import SnapKit
|
||||
import UIKit
|
||||
|
||||
/// 个人信息卡片行,展示左侧标题与右侧内容,可选点击与箭头。
|
||||
final class ProfileInfoRowView: UIControl {
|
||||
|
||||
enum AccessoryStyle {
|
||||
case none
|
||||
case chevron
|
||||
case action(String)
|
||||
}
|
||||
|
||||
private let titleLabel = UILabel()
|
||||
private let valueLabel = UILabel()
|
||||
private let accessoryLabel = UILabel()
|
||||
private let chevronView = UIImageView()
|
||||
private let divider = UIView()
|
||||
private let badgeContainer = UIView()
|
||||
private var badgeView: ProfileStatusBadgeView?
|
||||
|
||||
var showsDivider = true {
|
||||
didSet { divider.isHidden = !showsDivider }
|
||||
}
|
||||
|
||||
init(title: String) {
|
||||
super.init(frame: .zero)
|
||||
titleLabel.text = title
|
||||
setupUI()
|
||||
}
|
||||
|
||||
@available(*, unavailable)
|
||||
required init?(coder: NSCoder) {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
|
||||
func configure(
|
||||
value: String?,
|
||||
valueColor: UIColor = AppColor.text333,
|
||||
accessory: AccessoryStyle = .none,
|
||||
badge: ProfileStatusBadgeView.Style? = nil
|
||||
) {
|
||||
valueLabel.text = value
|
||||
valueLabel.textColor = valueColor
|
||||
valueLabel.isHidden = badge != nil
|
||||
badgeContainer.isHidden = badge == nil
|
||||
|
||||
if let badge {
|
||||
if badgeView == nil {
|
||||
let view = ProfileStatusBadgeView()
|
||||
badgeContainer.addSubview(view)
|
||||
view.snp.makeConstraints { make in
|
||||
make.edges.equalToSuperview()
|
||||
}
|
||||
badgeView = view
|
||||
}
|
||||
badgeView?.apply(style: badge, text: value ?? "")
|
||||
}
|
||||
|
||||
accessoryLabel.isHidden = true
|
||||
chevronView.isHidden = true
|
||||
switch accessory {
|
||||
case .none:
|
||||
break
|
||||
case .chevron:
|
||||
chevronView.isHidden = false
|
||||
case .action(let text):
|
||||
accessoryLabel.text = text
|
||||
accessoryLabel.isHidden = false
|
||||
chevronView.isHidden = false
|
||||
}
|
||||
}
|
||||
|
||||
private func setupUI() {
|
||||
titleLabel.font = .systemFont(ofSize: 14)
|
||||
titleLabel.textColor = UIColor(hex: 0x4B5563)
|
||||
titleLabel.setContentHuggingPriority(.required, for: .horizontal)
|
||||
|
||||
valueLabel.font = .systemFont(ofSize: 14)
|
||||
valueLabel.textAlignment = .right
|
||||
valueLabel.numberOfLines = 1
|
||||
|
||||
accessoryLabel.font = .systemFont(ofSize: 14)
|
||||
accessoryLabel.textColor = AppColor.primary
|
||||
|
||||
chevronView.image = UIImage(systemName: "chevron.right")
|
||||
chevronView.tintColor = AppColor.text666
|
||||
chevronView.contentMode = .scaleAspectFit
|
||||
|
||||
divider.backgroundColor = UIColor(hex: 0xE5E7EB)
|
||||
|
||||
addSubview(titleLabel)
|
||||
addSubview(valueLabel)
|
||||
addSubview(badgeContainer)
|
||||
addSubview(accessoryLabel)
|
||||
addSubview(chevronView)
|
||||
addSubview(divider)
|
||||
|
||||
snp.makeConstraints { make in
|
||||
make.height.equalTo(52)
|
||||
}
|
||||
titleLabel.snp.makeConstraints { make in
|
||||
make.leading.equalToSuperview()
|
||||
make.centerY.equalToSuperview()
|
||||
make.width.equalTo(102)
|
||||
}
|
||||
chevronView.snp.makeConstraints { make in
|
||||
make.trailing.equalToSuperview()
|
||||
make.centerY.equalToSuperview()
|
||||
make.width.height.equalTo(16)
|
||||
}
|
||||
accessoryLabel.snp.makeConstraints { make in
|
||||
make.trailing.equalTo(chevronView.snp.leading).offset(-4)
|
||||
make.centerY.equalToSuperview()
|
||||
}
|
||||
valueLabel.snp.makeConstraints { make in
|
||||
make.leading.greaterThanOrEqualTo(titleLabel.snp.trailing).offset(8)
|
||||
make.trailing.equalTo(chevronView.snp.leading).offset(-4)
|
||||
make.centerY.equalToSuperview()
|
||||
}
|
||||
badgeContainer.snp.makeConstraints { make in
|
||||
make.leading.equalTo(titleLabel.snp.trailing).offset(8)
|
||||
make.centerY.equalToSuperview()
|
||||
make.trailing.lessThanOrEqualTo(chevronView.snp.leading).offset(-8)
|
||||
}
|
||||
divider.snp.makeConstraints { make in
|
||||
make.leading.trailing.bottom.equalToSuperview()
|
||||
make.height.equalTo(0.5)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user