85 lines
3.8 KiB
Swift
85 lines
3.8 KiB
Swift
import SnapKit
|
|
import UIKit
|
|
|
|
/// 注销页面共用的轻量视觉组件,仅负责颜色、字号和布局,不包含业务状态。
|
|
@MainActor
|
|
enum StoreAccountDeregistrationStyle {
|
|
/// 创建支持多行的系统字体标签。
|
|
static func label(_ text: String = "", size: CGFloat = 15, weight: UIFont.Weight = .regular,
|
|
color: UIColor = AppColor.textPrimary) -> UILabel {
|
|
let label = UILabel()
|
|
label.text = text
|
|
label.font = .systemFont(ofSize: size, weight: weight)
|
|
label.textColor = color
|
|
label.numberOfLines = 0
|
|
return label
|
|
}
|
|
|
|
/// 创建统一间距的纵向内容组。
|
|
static func stack(_ views: [UIView], spacing: CGFloat = 12) -> UIStackView {
|
|
let stack = UIStackView(arrangedSubviews: views)
|
|
stack.axis = .vertical
|
|
stack.spacing = spacing
|
|
return stack
|
|
}
|
|
|
|
/// 白色圆角卡片,内容由页面提供。
|
|
static func card(_ content: UIView) -> UIView {
|
|
let card = UIView()
|
|
card.backgroundColor = .white
|
|
card.layer.cornerRadius = 16
|
|
card.addSubview(content)
|
|
content.snp.makeConstraints { $0.edges.equalToSuperview().inset(16) }
|
|
return card
|
|
}
|
|
|
|
/// 统一主次按钮;禁用态及加载期间不依赖系统默认的灰底样式。
|
|
static func button(_ title: String, id: String, primary: Bool = true) -> UIButton {
|
|
let button = UIButton(type: .system)
|
|
button.accessibilityIdentifier = id
|
|
configure(button, title: title, primary: primary)
|
|
button.snp.makeConstraints { $0.height.greaterThanOrEqualTo(50) }
|
|
return button
|
|
}
|
|
|
|
/// 更新按钮角色和文案,保留清晰的主次关系。
|
|
static func configure(_ button: UIButton, title: String, primary: Bool = true) {
|
|
var config = primary ? UIButton.Configuration.filled() : .plain()
|
|
config.title = title
|
|
config.baseBackgroundColor = AppColor.primary
|
|
config.baseForegroundColor = primary ? .white : AppColor.primary
|
|
config.background.cornerRadius = 12
|
|
config.contentInsets = .init(top: 14, leading: 16, bottom: 14, trailing: 16)
|
|
config.titleTextAttributesTransformer = UIConfigurationTextAttributesTransformer { attributes in
|
|
var attributes = attributes
|
|
attributes.font = UIFont.systemFont(ofSize: 16, weight: .semibold)
|
|
return attributes
|
|
}
|
|
button.configuration = config
|
|
button.configurationUpdateHandler = { button in
|
|
let enabled = button.isEnabled
|
|
var updated = button.configuration
|
|
updated?.background.backgroundColorTransformer = UIConfigurationColorTransformer { _ in
|
|
primary ? (enabled ? AppColor.primary : AppColor.primary.withAlphaComponent(0.12)) : .clear
|
|
}
|
|
updated?.titleTextAttributesTransformer = UIConfigurationTextAttributesTransformer { attributes in
|
|
var attributes = attributes
|
|
attributes.font = UIFont.systemFont(ofSize: 16, weight: .semibold)
|
|
attributes.foregroundColor = enabled ? (primary ? .white : AppColor.primary) : AppColor.textSecondary
|
|
return attributes
|
|
}
|
|
button.configuration = updated
|
|
}
|
|
}
|
|
|
|
/// 以统一的SF Symbol展示提示图标,不加载额外图片资源。
|
|
static func icon(_ name: String, size: CGFloat = 22) -> UIImageView {
|
|
let image = UIImageView(image: UIImage(systemName: name,
|
|
withConfiguration: UIImage.SymbolConfiguration(pointSize: size, weight: .medium)))
|
|
image.tintColor = AppColor.primary
|
|
image.contentMode = .scaleAspectFit
|
|
image.setContentHuggingPriority(.required, for: .horizontal)
|
|
return image
|
|
}
|
|
}
|