mirror of
https://codeberg.org/comaps/comaps
synced 2026-01-04 03:43:46 +00:00
To expand with full Organic Maps and Maps.ME commits history run: git remote add om-historic [om-historic.git repo url] git fetch --tags om-historic git replace squashed-history historic-commits
60 lines
1.5 KiB
Swift
60 lines
1.5 KiB
Swift
import UIKit
|
|
|
|
final class CalendarHeader: UICollectionReusableView {
|
|
let monthLabel = UILabel()
|
|
let vStack = UIStackView()
|
|
let weekdaysStack = UIStackView()
|
|
var weekdayLabels: [UILabel] = []
|
|
var theme = DatePickerViewTheme() {
|
|
didSet {
|
|
updateTheme()
|
|
}
|
|
}
|
|
|
|
private func updateTheme() {
|
|
backgroundColor = theme.monthHeaderBackgroundColor
|
|
monthLabel.textColor = theme.monthHeaderColor
|
|
monthLabel.font = theme.monthHeaderFont
|
|
weekdayLabels.forEach {
|
|
$0.textColor = theme.weekdaySymbolsColor
|
|
$0.font = theme.weekdaySymbolsFont
|
|
}
|
|
}
|
|
|
|
override init(frame: CGRect) {
|
|
super.init(frame: frame)
|
|
addSubview(vStack)
|
|
vStack.alignToSuperview()
|
|
vStack.addArrangedSubview(monthLabel)
|
|
vStack.addArrangedSubview(weekdaysStack)
|
|
for _ in 0..<7 {
|
|
let label = UILabel()
|
|
label.textAlignment = .center
|
|
weekdayLabels.append(label)
|
|
weekdaysStack.addArrangedSubview(label)
|
|
}
|
|
vStack.axis = .vertical
|
|
vStack.distribution = .fillEqually
|
|
weekdaysStack.axis = .horizontal
|
|
weekdaysStack.distribution = .fillEqually
|
|
monthLabel.textAlignment = .center
|
|
}
|
|
|
|
required init?(coder: NSCoder) {
|
|
fatalError("init(coder:) has not been implemented")
|
|
}
|
|
|
|
override func prepareForReuse() {
|
|
monthLabel.text = nil
|
|
}
|
|
|
|
func config(_ month: String, weekdays: [String], firstWeekday: Int) {
|
|
monthLabel.text = month
|
|
for i in 0..<7 {
|
|
let index = (i + firstWeekday - 1) % 7
|
|
let label = weekdayLabels[i]
|
|
label.text = weekdays[index]
|
|
}
|
|
}
|
|
}
|