Objective-C UIControl Category Inspired By JQuery Adding Many Blocks-Based Events

Previously I mentioned a great library providing a large number of block utilities called BlocksKit enhancing many classes within the iOS SDK to utilize blocks.

Here’s a library from Mysterious Trousers called MTControl inspired by JQuery providing an add-on library for many UIControl based objects that allows you to handle events using blocks.

Here’s an example from the readme using the MTControl enhanced UIButton:

UIButton *button = [UIButton buttonWithType:UIButtonTypeContactAdd];

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

Another example showing MTControl working with A UITextField:

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

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

And here’s a listing of the events provided by MTControl:

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

You can find MTControlBlocks on Github here.

Blocks can definitely make things much easier.

DeliciousTwitterFacebookRedditLinkedInEmail

Original article: Objective-C UIControl Category Inspired By JQuery Adding Many Blocks-Based Events

©2013 iOS App Dev Libraries, Controls, Tutorials, Examples and Tools. All Rights Reserved.

Leave a Reply

Your email address will not be published. Required fields are marked *