Skip to content

Instantly share code, notes, and snippets.

@aaronlab
Last active April 5, 2021 14:54
Show Gist options
  • Save aaronlab/9aae67004f4c871287a6c768ddee7504 to your computer and use it in GitHub Desktop.
Save aaronlab/9aae67004f4c871287a6c768ddee7504 to your computer and use it in GitHub Desktop.
UIButton Animation Extension Solution
import UIKit
// MARK: - Custom Button Gesture
extension UIButton {
/**
This part will let you use the system default animation for the UIButton,
when you use the custom UIButton class.
*/
override open func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
isHighlighted = true
super.touchesBegan(touches, with: event)
}
override open func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
isHighlighted = false
super.touchesEnded(touches, with: event)
}
override open func touchesCancelled(_ touches: Set<UITouch>, with event: UIEvent?) {
isHighlighted = false
super.touchesCancelled(touches, with: event)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment