Skip to content

Instantly share code, notes, and snippets.

@AknEp
Created June 10, 2016 10:29
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 AknEp/9c8485022fdad269f33b4a079df4da65 to your computer and use it in GitHub Desktop.
Save AknEp/9c8485022fdad269f33b4a079df4da65 to your computer and use it in GitHub Desktop.
影つきの UIButton のサブクラスです。
class ShadowedButton : UIButton {
override func willMoveToSuperview(newSuperview: UIView?) {
super.willMoveToSuperview(newSuperview)
self.addTarget(self, action: #selector(addShadow), forControlEvents: UIControlEvents.TouchDown)
self.addTarget(self, action: #selector(addShadow), forControlEvents: UIControlEvents.TouchDragEnter)
self.addTarget(self, action: #selector(removeShadow), forControlEvents: UIControlEvents.TouchDragExit)
self.addTarget(self, action: #selector(removeShadow), forControlEvents: UIControlEvents.TouchUpInside)
}
func addShadow(){
self.backgroundColor = UIColor(white: 0.0, alpha: 0.1)
}
func removeShadow(){
self.backgroundColor = UIColor.clearColor()
}
override func removeFromSuperview() {
super.removeFromSuperview()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment