Tusker/Tusker/Views/ToggleableButton.swift

37 lines
801 B
Swift

//
// ToggleableButton.swift
// Tusker
//
// Created by Shadowfacts on 5/13/23.
// Copyright © 2023 Shadowfacts. All rights reserved.
//
import UIKit
class ToggleableButton: UIButton {
let activeColor: UIColor
var active: Bool {
didSet {
if var config = self.configuration {
config.baseForegroundColor = active ? activeColor : nil
self.configuration = config
} else {
tintColor = active ? activeColor : nil
}
}
}
init(activeColor: UIColor) {
self.activeColor = activeColor
self.active = false
super.init(frame: .zero)
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}