Skip to content

Instantly share code, notes, and snippets.

@jeffaburt
Created August 8, 2016 18:45
Show Gist options
  • Save jeffaburt/be6575335cf3b97fc06bb55c125d89f4 to your computer and use it in GitHub Desktop.
Save jeffaburt/be6575335cf3b97fc06bb55c125d89f4 to your computer and use it in GitHub Desktop.
It's really annoying that only the image fades when you tap on a button. By subclassing this, the entire button will fade.
import UIKit
class FadeWhenHiglightedButton: UIButton {
private var initialAlpha: CGFloat!
override var highlighted: Bool {
didSet {
alpha = highlighted ? initialAlpha - 0.4 : initialAlpha
}
}
override init(frame: CGRect) {
super.init(frame: frame)
commonInit()
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
commonInit()
}
private func commonInit() {
initialAlpha = alpha
showsTouchWhenHighlighted = false
adjustsImageWhenHighlighted = false
reversesTitleShadowWhenHighlighted = false
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment