2019-10-22 10:31:25 +02:00
|
|
|
//
|
|
|
|
// VibrantButton.swift
|
|
|
|
// NetNewsWire-iOS
|
|
|
|
//
|
|
|
|
// Created by Maurice Parker on 10/22/19.
|
|
|
|
// Copyright © 2019 Ranchero Software. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import UIKit
|
|
|
|
|
|
|
|
class VibrantButton: UIButton {
|
2019-10-28 05:51:13 +01:00
|
|
|
|
|
|
|
@IBInspectable var backgroundHighlightColor: UIColor = AppAssets.secondaryAccentColor
|
2019-10-22 10:31:25 +02:00
|
|
|
|
|
|
|
override init(frame: CGRect) {
|
|
|
|
super.init(frame: frame)
|
|
|
|
commonInit()
|
|
|
|
}
|
|
|
|
required init?(coder: NSCoder) {
|
|
|
|
super.init(coder: coder)
|
|
|
|
commonInit()
|
|
|
|
}
|
|
|
|
|
|
|
|
private func commonInit() {
|
|
|
|
setTitleColor(AppAssets.vibrantTextColor, for: .highlighted)
|
2019-10-28 19:56:46 +01:00
|
|
|
let disabledColor = AppAssets.secondaryAccentColor.withAlphaComponent(0.5)
|
|
|
|
setTitleColor(disabledColor, for: .disabled)
|
2019-10-22 10:31:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
override var isHighlighted: Bool {
|
|
|
|
didSet {
|
2019-10-28 05:51:13 +01:00
|
|
|
backgroundColor = isHighlighted ? backgroundHighlightColor : nil
|
2019-10-22 10:31:25 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-23 19:01:26 +02:00
|
|
|
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
|
|
|
|
isHighlighted = true
|
|
|
|
super.touchesBegan(touches, with: event)
|
|
|
|
}
|
|
|
|
|
|
|
|
override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
|
|
|
|
isHighlighted = false
|
|
|
|
super.touchesEnded(touches, with: event)
|
|
|
|
}
|
|
|
|
|
|
|
|
override func touchesCancelled(_ touches: Set<UITouch>, with event: UIEvent?) {
|
|
|
|
isHighlighted = false
|
|
|
|
super.touchesCancelled(touches, with: event)
|
|
|
|
}
|
|
|
|
|
2019-10-22 10:31:25 +02:00
|
|
|
}
|