Skip to content

Instantly share code, notes, and snippets.

@jeffaburt
Created August 8, 2016 18:45
Show Gist options
  • Select an option

  • Save jeffaburt/be6575335cf3b97fc06bb55c125d89f4 to your computer and use it in GitHub Desktop.

Select an option

Save jeffaburt/be6575335cf3b97fc06bb55c125d89f4 to your computer and use it in GitHub Desktop.

Revisions

  1. jeffaburt created this gist Aug 8, 2016.
    28 changes: 28 additions & 0 deletions FadeWhenHighlightedButton.swift
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,28 @@
    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
    }
    }