Skip to content

Instantly share code, notes, and snippets.

@aprofromindia
Created December 12, 2019 11:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aprofromindia/67f078ee3e2a2474e1c2ea4feca80754 to your computer and use it in GitHub Desktop.
Save aprofromindia/67f078ee3e2a2474e1c2ea4feca80754 to your computer and use it in GitHub Desktop.
Swift UIButtonSwitch, toggles selected state upon touch
import UIKit
class ButtonSwitch: UIButton {
override func sendAction(_ action: Selector, to target: Any?, for event: UIEvent?) {
if allControlEvents == .touchUpInside {
isSelected.toggle()
}
super.sendAction(action, to: target, for: event)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment