2019-12-02 06:54:21 +01:00
|
|
|
|
|
|
|
final class Button : UIButton {
|
|
|
|
private let style: Style
|
|
|
|
|
|
|
|
enum Style {
|
2019-12-04 06:54:46 +01:00
|
|
|
case unimportant, regular, prominent
|
2019-12-02 06:54:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
init(style: Style) {
|
|
|
|
self.style = style
|
|
|
|
super.init(frame: .zero)
|
|
|
|
setUpStyle()
|
|
|
|
}
|
|
|
|
|
|
|
|
override init(frame: CGRect) {
|
|
|
|
preconditionFailure("Use init(style:) instead.")
|
|
|
|
}
|
|
|
|
|
|
|
|
required init?(coder: NSCoder) {
|
|
|
|
preconditionFailure("Use init(style:) instead.")
|
|
|
|
}
|
|
|
|
|
|
|
|
private func setUpStyle() {
|
|
|
|
let fillColor: UIColor
|
|
|
|
switch style {
|
|
|
|
case .unimportant: fillColor = Colors.unimportantButtonBackground
|
2019-12-04 06:54:46 +01:00
|
|
|
case .regular: fillColor = UIColor.clear
|
2019-12-02 06:54:21 +01:00
|
|
|
case .prominent: fillColor = UIColor.clear
|
|
|
|
}
|
|
|
|
let borderColor: UIColor
|
|
|
|
switch style {
|
|
|
|
case .unimportant: borderColor = Colors.unimportantButtonBackground
|
2019-12-04 06:54:46 +01:00
|
|
|
case .regular: borderColor = Colors.text
|
2019-12-02 06:54:21 +01:00
|
|
|
case .prominent: borderColor = Colors.accent
|
|
|
|
}
|
|
|
|
let textColor: UIColor
|
|
|
|
switch style {
|
|
|
|
case .unimportant: textColor = Colors.text
|
2019-12-04 06:54:46 +01:00
|
|
|
case .regular: textColor = Colors.text
|
2019-12-02 06:54:21 +01:00
|
|
|
case .prominent: textColor = Colors.accent
|
|
|
|
}
|
2019-12-04 06:54:46 +01:00
|
|
|
let height = Values.buttonHeight
|
2019-12-03 04:17:08 +01:00
|
|
|
set(.height, to: height)
|
|
|
|
layer.cornerRadius = height / 2
|
2019-12-02 06:54:21 +01:00
|
|
|
backgroundColor = fillColor
|
|
|
|
layer.borderColor = borderColor.cgColor
|
|
|
|
layer.borderWidth = Values.borderThickness
|
|
|
|
titleLabel!.font = Fonts.spaceMono(ofSize: Values.mediumFontSize)
|
|
|
|
setTitleColor(textColor, for: UIControl.State.normal)
|
|
|
|
}
|
|
|
|
}
|