Skip to content

Instantly share code, notes, and snippets.

@nathangitter
Created October 29, 2017 14:45
Show Gist options
  • Save nathangitter/3f2cf65a0c589ebe4ac556b9d9de7037 to your computer and use it in GitHub Desktop.
Save nathangitter/3f2cf65a0c589ebe4ac556b9d9de7037 to your computer and use it in GitHub Desktop.
class MyButton: UIButton {
var action: (() -> ())?
override init(frame: CGRect) {
super.init(frame: frame)
sharedInit()
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
sharedInit()
}
private func sharedInit() {
addTarget(self, action: #selector(touchUpInside), for: .touchUpInside)
}
@objc private func touchUpInside() {
action?()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment