Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Attach block handlers to UIControl objects jQuery style
Objective-C Ruby
Branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
MTControl.xcodeproj
MTControl
MTControlTests
.gitignore
LICENSE
MTControl.podspec
README.md

README.md

MTControl

Attach block handlers to UIControl objects jQuery style!

Installation

In your Podfile, add this line:

pod "MTControl"

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

NOTE: You may need to add -all_load to "Other Linker Flags" in your targets build settings if the pods library only contains categories.

Example Usage

A simple touch down event:

UIButton *button = [UIButton buttonWithType:UIButtonTypeContactAdd];

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

See? Just like jQuery! Works with any subclass of UIControl.

Let's try another:

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

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

And to remove the block (unbind):

[button removeBlocksForControlEvents:UIControlEventTouchDown];

Control Event Binding Methods:

touchDown
touchDownRepeat
touchDragInside
touchDragOutside
touchDragEnter
touchDragExit
touchUpInside
touchUpOutside
touchCancel
valueChanged
editingDidBegin
editingChanged
editingDidEnd
editingDidEndOnExit
allTouchEvents
allEditingEvents
Something went wrong with that request. Please try again.