45 lines
1.1 KiB
Swift
45 lines
1.1 KiB
Swift
//
|
|
// AppCardView.swift
|
|
// suixinkan
|
|
//
|
|
|
|
import SnapKit
|
|
import UIKit
|
|
|
|
/// 标准白底卡片容器,统一圆角与可选描边。
|
|
final class AppCardView: UIView {
|
|
|
|
/// 卡片内容区,子视图应添加到此 container。
|
|
let contentView = UIView()
|
|
|
|
private let showsBorder: Bool
|
|
|
|
/// - Parameter showsBorder: 是否显示 1px 描边(默认 false,flat 风格)。
|
|
init(showsBorder: Bool = false) {
|
|
self.showsBorder = showsBorder
|
|
super.init(frame: .zero)
|
|
setupUI()
|
|
}
|
|
|
|
@available(*, unavailable)
|
|
required init?(coder: NSCoder) {
|
|
fatalError("init(coder:) has not been implemented")
|
|
}
|
|
|
|
private func setupUI() {
|
|
backgroundColor = AppColor.cardBackground
|
|
layer.cornerRadius = AppRadius.md
|
|
clipsToBounds = true
|
|
|
|
if showsBorder {
|
|
layer.borderWidth = 1
|
|
layer.borderColor = AppColor.cardOutline.cgColor
|
|
}
|
|
|
|
addSubview(contentView)
|
|
contentView.snp.makeConstraints { make in
|
|
make.edges.equalToSuperview()
|
|
}
|
|
}
|
|
}
|