SwiftyEvents
这个库旨在在您需要为目标 UIControl 对象添加功能时使用 Swift 方式。
示例
要运行示例项目,请克隆仓库,然后首先从 Example 目录运行 pod install
。
安装
SwiftyEvents 可以通过 CocoaPods 构建。要安装它,只需将以下行添加到您的 Podfile 中:
pod 'SwiftyEvents'
用法
func addButton() {
let button = UIButton()
button.didTap {
print("Button did tap")
}
}
func addTextField() {
let textField = UITextField()
textField.didEdit {
print(textField.text)
}
}
func addSegmentedControl() {
let segmentedControl = UISegmentedControl()
segmentedControl.valueDidChange {
print("Value did change!")
}
}
或者您可以为自定义的 UIControl 使用它而不需要做任何事情。
func addCustomControl() {
let control = FancyCustomControl()
control.action(for: .touchUpInside) {
print("Tap event did fire")
}
}
支持的操作
- didTap
- UIButton
- valueDidChange
- UISegmentedControl
- UISwitch
- UISlider
- UIStepper
- UIRefreshControl
- didEdit
- UITextField
作者
Volkan Bicer, [email protected]
许可证
SwiftyEvents 根据 MIT 许可证可用。更多信息请参阅 LICENSE 文件。