ActionClosurable
使用
ActionClosurable 扩展了 UIControl
、UIButton
、UIRefreshControl
、UIGestureRecognizer
和 UIBarButtonItem
。它帮助您用闭包编写 swift 代码,而不是像以下那样使用 target 和 action
// UIControl
button.on(.touchDown) {
$0.backgroundColor = UIColor.redColor()
}
button.on(.touchUpOutside) {
$0.backgroundColor = UIColor.whiteColor()
}
// UIButton
button.onTap {
$0.enabled = false
}
// UIRefreshControl
tableView.refreshControl = UIRefreshControl { refreshControl in
DispatchQueue.main.asyncAfter(deadline: .now() + 5) {
refreshControl.endRefreshing()
}
}
// UIGestureRecognizer
label.addGestureRecognizer(UIPanGestureRecognizer { (gr) in
print("UIPanGestureRecognizer fire")
})
// UIBarButtonItem
let barButtonItem = UIBarButtonItem(title: "title", style: .plain) { _ in
print("barButtonItem title")
}
// And you can easily extend any NSObject subclasses!
您可以通过非常简单的方式扩展任何 NSObject 子类。请参阅资源代码 链接。
安装
ActionClosurable 通过 CocoaPods 提供。要安装它,只需在您的 Podfile 中添加以下行
pod "ActionClosurable"
ActionClosurable 通过 Carthage 提供。要安装它,只需在您的 Cartfile 中添加以下行
github "takasek/ActionClosurable"
作者
许可证
ActionClosurable 按照MIT许可证提供。更多信息请参阅LICENSE文件。