87 lines
2.8 KiB
Swift
87 lines
2.8 KiB
Swift
//
|
|
// PairGuideStepsView.swift
|
|
// QuickLocation
|
|
//
|
|
|
|
import UIKit
|
|
|
|
final class PairGuideStepsView: UIView {
|
|
private struct Step {
|
|
let number: String
|
|
let title: String
|
|
let color: UIColor
|
|
}
|
|
|
|
private let steps: [Step] = [
|
|
Step(number: "1", title: "新增配对应用", color: UIColor(hexStr: "#8B5CF6")),
|
|
Step(number: "2", title: "选择相同应用", color: UIColor(hexStr: "#16B3FF")),
|
|
Step(number: "3", title: "完成配对", color: UIColor(hexStr: "#22C55E"))
|
|
]
|
|
|
|
private let circleSize: CGFloat = 28
|
|
private let dashLayer = CAShapeLayer()
|
|
|
|
override init(frame: CGRect) {
|
|
super.init(frame: frame)
|
|
backgroundColor = .clear
|
|
dashLayer.strokeColor = UIColor(hexStr: "#D1D5DB").cgColor
|
|
dashLayer.lineWidth = 1
|
|
dashLayer.lineDashPattern = [3, 3]
|
|
dashLayer.fillColor = UIColor.clear.cgColor
|
|
layer.addSublayer(dashLayer)
|
|
}
|
|
|
|
required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") }
|
|
|
|
override var intrinsicContentSize: CGSize {
|
|
CGSize(width: UIView.noIntrinsicMetric, height: 72)
|
|
}
|
|
|
|
override func layoutSubviews() {
|
|
super.layoutSubviews()
|
|
subviews.forEach { $0.removeFromSuperview() }
|
|
|
|
let columnWidth = bounds.width / 3
|
|
let circleY = circleSize / 2 + 2
|
|
let centers = (0..<steps.count).map { columnWidth * (CGFloat($0) + 0.5) }
|
|
|
|
let path = UIBezierPath()
|
|
path.move(to: CGPoint(x: centers.first ?? 0, y: circleY))
|
|
path.addLine(to: CGPoint(x: centers.last ?? bounds.width, y: circleY))
|
|
dashLayer.path = path.cgPath
|
|
dashLayer.frame = bounds
|
|
|
|
for (index, step) in steps.enumerated() {
|
|
let centerX = centers[index]
|
|
|
|
let circle = UILabel(frame: CGRect(
|
|
x: centerX - circleSize / 2,
|
|
y: 0,
|
|
width: circleSize,
|
|
height: circleSize
|
|
))
|
|
circle.text = step.number
|
|
circle.font = FontManager.boboBold(14)
|
|
circle.textColor = .white
|
|
circle.textAlignment = .center
|
|
circle.backgroundColor = step.color
|
|
circle.layer.cornerRadius = circleSize / 2
|
|
circle.clipsToBounds = true
|
|
addSubview(circle)
|
|
|
|
let label = UILabel()
|
|
label.text = step.title
|
|
label.font = .systemFont(ofSize: 12, weight: .medium)
|
|
label.textColor = UIColor(hexStr: "#293445")
|
|
label.textAlignment = .center
|
|
label.frame = CGRect(
|
|
x: columnWidth * CGFloat(index) + 4,
|
|
y: circleSize + 10,
|
|
width: columnWidth - 8,
|
|
height: 34
|
|
)
|
|
addSubview(label)
|
|
}
|
|
}
|
|
}
|