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];
- <a href='#' class='small-button smallblue'><span></span></a>;
- [_model fetchFromServer:@"http://mysterioustrousers.com" success:^(BOOL success){
- [_spinner stop];
- }];
- }];
UIButton *button = [UIButton buttonWithType:UIButtonTypeContactAdd];
<a href='#' class='small-button smallblue'><span></span></a>;
[_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 = @"";
- }];
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
touchDown touchDownRepeat touchDragInside touchDragOutside touchDragEnter touchDragExit touchUpInside touchUpOutside touchCancel valueChanged editingDidBegin editingChanged editingDidEnd editingDidEndOnExit allTouchEvents allEditingEvents
You can find MTControlBlocks
Blocks can definitely make things much easier.



Recent Comments