Files
NetNewsWire/iOS/UIKit Extensions/VibrantButton.swift
T

51 lines
1.3 KiB
Swift
Raw Normal View History

2019-10-22 03:31:25 -05:00
//
// VibrantButton.swift
// NetNewsWire-iOS
//
// Created by Maurice Parker on 10/22/19.
// Copyright © 2019 Ranchero Software. All rights reserved.
//
import UIKit
final class VibrantButton: UIButton {
2025-11-05 11:22:10 -08:00
2025-11-19 10:38:18 -08:00
@IBInspectable var backgroundHighlightColor: UIColor = Assets.Colors.secondaryAccent
2019-10-22 03:31:25 -05:00
override init(frame: CGRect) {
super.init(frame: frame)
commonInit()
}
required init?(coder: NSCoder) {
super.init(coder: coder)
commonInit()
}
2025-11-05 11:22:10 -08:00
2019-10-22 03:31:25 -05:00
private func commonInit() {
2025-11-19 10:38:18 -08:00
setTitleColor(Assets.Colors.vibrantText, for: .highlighted)
let disabledColor = Assets.Colors.secondaryAccent.withAlphaComponent(0.5)
2019-10-28 13:56:46 -05:00
setTitleColor(disabledColor, for: .disabled)
2019-10-22 03:31:25 -05:00
}
override var isHighlighted: Bool {
didSet {
2019-10-28 00:51:13 -04:00
backgroundColor = isHighlighted ? backgroundHighlightColor : nil
2019-10-22 03:31:25 -05:00
}
}
2019-10-23 12:01:26 -05: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)
}
2025-11-05 11:22:10 -08:00
2019-10-22 03:31:25 -05:00
}