Skip to content

Instantly share code, notes, and snippets.

@natebirkholz
Created August 9, 2021 15:52
Show Gist options
  • Save natebirkholz/3ff7e5eb20f6b6bf43a1b5881dec5a2d to your computer and use it in GitHub Desktop.
Save natebirkholz/3ff7e5eb20f6b6bf43a1b5881dec5a2d to your computer and use it in GitHub Desktop.
class ClosureButton: UIButton {
private var actionHandler: (() -> ())?
func addClosureForEvent(_ event: UIControlEvents, closure: @escaping () ->()) {
self.addTarget(self, action: #selector(handleAction), for: event)
}
@objc private func handleAction() {
actionHandler?()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment