Get Updates By E-mail 

Article Written By:
Johann Dowa

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.


  •  
  •  
  •  
  •  
  •  

Submit A Resource

Have you created a useful tutorial, library or tool for iOS development that you would like to get in front of our 300,000+ monthly page views from iOS developers?

You can submit the url here.

The resources we feel will appeal to our readers the most will be posted on the front page.

Comments