MTControl 0.0.4

MTControl 0.0.4

测试已测试
语言语言 Obj-CObjective C
许可证 BSD
发布最后发布2014年12月

Adam Kirk 维护。



MTControl 0.0.4

  • Adam Kirk

类似 jQuery 风格将块处理程序附加到 UIControl 对象!

安装

在您的 Podfile 中添加以下行:

pod "MTControl"

pod? => https://github.com/CocoaPods/CocoaPods/

注意:如果 pods 库只包含类别,您可能需要在目标构建设置中添加 "-all_load" 到 "其他链接器标志"。

示例用法

简单的触摸事件

UIButton *button = [UIButton buttonWithType:UIButtonTypeContactAdd];

[button touchDown:^(UIEvent *event) {
    [_spinner start];
    [_model fetchFromServer:@"http://mysterioustrousers.com" success:^(BOOL success){
        [_spinner stop];
    }];
}];

看?就像 jQuery!它与任何继承自 UIControl 的子类都兼容。

让我们尝试另一个

UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, 300, 40)];

[textField editingDidBegin:^(UIEvent *event) {
    textField.text = @"";
}];

要移除块(解绑):

[button removeBlocksForControlEvents:UIControlEventTouchDown];

控制事件绑定方法

touchDown
touchDownRepeat
touchDragInside
touchDragOutside
touchDragEnter
touchDragExit
touchUpInside
touchUpOutside
touchCancel
valueChanged
editingDidBegin
editingChanged
editingDidEnd
editingDidEndOnExit
allTouchEvents
allEditingEvents