Repo created

This commit is contained in:
Fr4nz D13trich 2025-11-22 13:58:55 +01:00
parent 4af19165ec
commit 68073add76
12458 changed files with 12350765 additions and 2 deletions

View file

@ -0,0 +1,65 @@
class DifficultyView: UIView {
private let stackView = UIStackView()
private var views:[UIView] = []
var difficulty: ElevationDifficulty = .easy {
didSet {
updateView()
}
}
var colors: [UIColor] = [.gray, .green, .orange, .red]
{
didSet {
updateView()
}
}
var emptyColor: UIColor = UIColor.gray {
didSet {
updateView()
}
}
private let bulletSize = CGSize(width: 10, height: 10)
private let bulletSpacing: CGFloat = 5
private let difficultyLevelCount = 3
override init(frame: CGRect) {
super.init(frame: frame)
initComponent()
}
required init?(coder: NSCoder) {
super.init(coder: coder)
initComponent()
}
private func initComponent() {
self.addSubview(stackView)
stackView.frame = bounds
stackView.distribution = .fillEqually
stackView.axis = .horizontal
stackView.spacing = bulletSpacing
stackView.alignment = .fill
for _ in 0..<difficultyLevelCount {
let view = UIView()
stackView.addArrangedSubview(view)
view.layer.setCornerRadius(.custom(bulletSize.height / 2))
views.append(view)
}
}
private func updateView() {
guard colors.count > difficulty.rawValue else {
assertionFailure("No fill color")
return
}
let fillColor = colors[difficulty.rawValue]
for (idx, view) in views.enumerated() {
if idx < difficulty.rawValue {
view.backgroundColor = fillColor
} else {
view.backgroundColor = emptyColor
}
}
}
}