Files
suixinkan_uikit/suixinkan/UI/Statistics/StatisticsPeriodButton.swift

49 lines
1.3 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// StatisticsPeriodButton.swift
// suixinkan
//
import SnapKit
import UIKit
/// pill Android `PeriodButton`
final class StatisticsPeriodButton: UIButton {
var periodTitle: String = "" {
didSet { setTitle(periodTitle, for: .normal) }
}
override var isSelected: Bool {
didSet { updateAppearance() }
}
override func layoutSubviews() {
super.layoutSubviews()
layer.cornerRadius = bounds.height / 2
}
override init(frame: CGRect) {
super.init(frame: frame)
setupUI()
}
@available(*, unavailable)
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
private func setupUI() {
titleLabel?.font = .app(.bodyMedium)
layer.cornerCurve = .continuous
clipsToBounds = true
contentEdgeInsets = UIEdgeInsets(top: 6, left: 20, bottom: 6, right: 20)
updateAppearance()
}
private func updateAppearance() {
backgroundColor = isSelected ? AppColor.primary : AppColor.inputBackground
setTitleColor(isSelected ? .white : AppColor.textSecondary, for: .normal)
titleLabel?.font = .systemFont(ofSize: 14, weight: isSelected ? .semibold : .medium)
}
}