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:
[button touchDown:^(UIEvent *event) {
[_spinner start];
[_model fetchFromServer:@"http://mysterioustrousers.com" success:^(BOOL success){
[_spinner stop];
}];
}];
Another example showing MTControl working with A UITextField:
[textField editingDidBegin:^(UIEvent *event) {
textField.text = @"";
}];
And here’s a listing of the events provided by MTControl:
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.
- Tutorial: How To Work Some Objective-C Magic To Add Blocks Support Into UIMenuItem
- Open Source: Massive Collection Of Objective-C Blocks Extensions
- News: New iOS Facebook SDK Released With New Native UI Views, Blocks, And More
- Handy Cheat Sheet For Using Objective-C Blocks (Closures)
- Tutorial: Objective-C Blocks (Closures) For Beginners
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.





