完善账号切换展示、首页菜单图标与有线传输设置 chip。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-07-15 14:59:31 +08:00
parent 5eef31b8da
commit ce6de76055
18 changed files with 321 additions and 130 deletions

View File

@ -0,0 +1,88 @@
//
// WiredTransferSettingChipButton.swift
// suixinkan
//
import SnapKit
import UIKit
/// 线 chip `UIButton` title
final class WiredTransferSettingChipButton: UIButton {
private let titleLabelView = UILabel()
private let chevronView = UIImageView()
private var titleTrailingToSuperviewConstraint: Constraint?
private var titleTrailingToChevronConstraint: Constraint?
///
var showsChevron: Bool {
didSet { updateChevronLayout() }
}
///
private(set) var titleText: String = ""
/// chip
/// - Parameter showsChevron:
init(showsChevron: Bool = false) {
self.showsChevron = showsChevron
super.init(frame: .zero)
setupUI()
updateChevronLayout()
}
@available(*, unavailable)
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
/// chip
func apply(title: String) {
titleText = title
titleLabelView.text = title
accessibilityLabel = title
}
private func setupUI() {
backgroundColor = AppColor.pageBackground
layer.cornerRadius = 8
layer.borderWidth = 1
layer.borderColor = AppColor.border.cgColor
titleLabelView.font = .systemFont(ofSize: 11)
titleLabelView.textColor = AppColor.textTertiary
titleLabelView.lineBreakMode = .byTruncatingTail
titleLabelView.isUserInteractionEnabled = false
chevronView.image = UIImage(systemName: "chevron.down")?
.withConfiguration(UIImage.SymbolConfiguration(pointSize: 13, weight: .semibold))
chevronView.tintColor = AppColor.textTertiary
chevronView.contentMode = .scaleAspectFit
chevronView.isUserInteractionEnabled = false
addSubview(titleLabelView)
addSubview(chevronView)
titleLabelView.snp.makeConstraints { make in
make.leading.equalToSuperview().offset(10)
make.centerY.equalToSuperview()
titleTrailingToSuperviewConstraint = make.trailing.lessThanOrEqualToSuperview().offset(-10).constraint
titleTrailingToChevronConstraint = make.trailing.lessThanOrEqualTo(chevronView.snp.leading).offset(-4).constraint
}
chevronView.snp.makeConstraints { make in
make.trailing.equalToSuperview().offset(-10)
make.centerY.equalToSuperview()
make.size.equalTo(16)
}
}
private func updateChevronLayout() {
chevronView.isHidden = !showsChevron
if showsChevron {
titleTrailingToSuperviewConstraint?.deactivate()
titleTrailingToChevronConstraint?.activate()
} else {
titleTrailingToChevronConstraint?.deactivate()
titleTrailingToSuperviewConstraint?.activate()
}
}
}