[![CI Status](http://img.shields.io/travis/Yoshitaka Seki/ActionClosurable.svg?style=flat)](https://travis-ci.org/Yoshitaka Seki/ActionClosurable)
ActionClosurable extends UIControl
, UIButton
, UIGestureRecognizer
, UIBarButtonItem
and NSTimer
.
It helps writing swifty code with closure, instead of target and action like below:
// UIControl
button.on(.TouchDown) {
$0.backgroundColor = UIColor.redColor()
}
button.on(.TouchUpOutside) {
$0.backgroundColor = UIColor.whiteColor()
}
// UIButton
button.onTap {
$0.enabled = false
}
// UIGestureRecognizer
label.addGestureRecognizer(UIPanGestureRecognizer { gr in
print("UIPanGestureRecognizer fire")
})
// UIBarButtonItem
let barButtonItem = UIBarButtonItem(title: "title", style: .Plain, closure: { _ in
print("barButtonItem title")
})
// NSTimer
var i = 5
self.timer = NSTimer.scheduledTimerWithTimeInterval(1, repeats: true) { [weak self] timer in
print("timer", i)
i -= 1
if i <= 0 {
timer.invalidate()
self?.timer = nil
}
}
// And you can easily extend any NSObject subclasses!
And you can extend any NSObject subclasses in very easy way. Refer to the source.
ActionClosurable is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod "ActionClosurable"
ActionClosurable is available through Carthage. To install it, simply add the following line to your Cartfile:
github "takasek/ActionClosurable"
ActionClosurable is available under the MIT license. See the LICENSE file for more info.