Files
suixinkan_uikit/suixinkan/UI/Home/Views/AllFunctionMenuCell.swift
汉秋 005349f8e6 模块化 AppStore 并完善素材管理与个人空间设置。
将会话、权限、位置、收款与排队存储拆分为独立模块,同步更新各 ViewModel 与单元测试,并补充素材管理 UI 与个人空间设置交互。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-13 11:01:08 +08:00

115 lines
3.6 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// AllFunctionMenuCell.swift
// suixinkan
//
import SnapKit
import UIKit
///
final class AllFunctionMenuCell: UICollectionViewCell {
static let reuseIdentifier = "AllFunctionMenuCell"
///
enum ActionStyle {
case none
case add
case remove
}
private let cardView = UIView()
private let contentStackView = UIStackView()
private let iconView = UIImageView()
private let titleLabel = UILabel()
private let actionImageView = UIImageView()
override var isHighlighted: Bool {
didSet {
cardView.alpha = isHighlighted ? 0.72 : 1
}
}
override init(frame: CGRect) {
super.init(frame: frame)
setupUI()
}
@available(*, unavailable)
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
///
func apply(menu: HomeMenuItem, actionStyle: ActionStyle) {
iconView.image = UIImage(named: menu.iconName) ?? UIImage(systemName: menu.iconName)
titleLabel.text = menu.title
accessibilityLabel = menu.title
switch actionStyle {
case .none:
actionImageView.isHidden = true
accessibilityTraits = []
accessibilityHint = nil
case .add:
actionImageView.isHidden = false
actionImageView.image = UIImage(systemName: "plus.circle.fill")
actionImageView.tintColor = AppColor.primary
accessibilityTraits = .button
accessibilityHint = "添加到常用应用"
case .remove:
actionImageView.isHidden = false
actionImageView.image = UIImage(systemName: "minus.circle.fill")
actionImageView.tintColor = AppColor.danger
accessibilityTraits = .button
accessibilityHint = "移出常用应用"
}
}
private func setupUI() {
contentView.backgroundColor = .clear
cardView.backgroundColor = .white
cardView.layer.cornerRadius = AppRadius.md
cardView.clipsToBounds = true
iconView.tintColor = AppColor.primary
iconView.contentMode = .scaleAspectFit
contentStackView.axis = .vertical
contentStackView.alignment = .center
contentStackView.spacing = AppSpacing.sm
contentStackView.isUserInteractionEnabled = false
titleLabel.font = .app(.body)
titleLabel.textColor = AppColor.textSecondary
titleLabel.textAlignment = .center
titleLabel.numberOfLines = 2
isAccessibilityElement = true
actionImageView.contentMode = .scaleAspectFit
actionImageView.isUserInteractionEnabled = false
contentView.addSubview(cardView)
cardView.addSubview(contentStackView)
cardView.addSubview(actionImageView)
contentStackView.addArrangedSubview(iconView)
contentStackView.addArrangedSubview(titleLabel)
cardView.snp.makeConstraints { make in
make.edges.equalToSuperview()
}
contentStackView.snp.makeConstraints { make in
make.center.equalToSuperview()
make.leading.trailing.equalToSuperview().inset(AppSpacing.xxs)
}
iconView.snp.makeConstraints { make in
make.width.height.equalTo(26)
}
actionImageView.snp.makeConstraints { make in
make.top.trailing.equalToSuperview().inset(AppSpacing.xxs)
make.width.height.equalTo(20)
}
}
}