Deprecated, please use RxCocoa
This pod is used by
SHUIKitBlocks
as part of many components covering to plug the holes missing from Foundation, UIKit, CoreLocation, GameKit, MapKit and other aspects of an iOS application's architecture.
Category on top of UIBarButtonItem.
The blocks are automatically removed once the item is gone, so it isn't necessary to clean up - Swizzle Free(™)
pod 'SHBarButtonItemBlocks'
Put this either in specific files or your project prefix file
#import "UIBarButtonItem+SHBarButtonItemBlocks.h"
or
#import "SHBarButtonItemBlocks.h"
#pragma mark -
#pragma mark Init
+(instancetype)SH_barButtonItemWithBarButtonSystemItem:(UIBarButtonSystemItem)systemItem
withBlock:(SHBarButtonItemBlock)theBlock;
+(instancetype)SH_barButtonItemWithImage:(UIImage *)image style:(UIBarButtonItemStyle)style
withBlock:(SHBarButtonItemBlock)theBlock;
+(instancetype)SH_barButtonItemWithTitle:(NSString *)title style:(UIBarButtonItemStyle)style
withBlock:(SHBarButtonItemBlock)theBlock;
#pragma mark -
#pragma mark Add
-(void)SH_addBlock:(SHBarButtonItemBlock)theBlock;
#pragma mark -
#pragma mark Remove
-(void)SH_removeBlock:(SHBarButtonItemBlock)theBlock;
-(void)SH_removeAllBlocks;
#pragma mark -
#pragma mark Properties
#pragma mark -
#pragma mark Getters
@property(nonatomic,readonly) NSSet * SH_blocks;
UIBarButtonItem * button = [UIBarButtonItem SH_barButtonItemWithTitle:@"Clear blocks" style:UIBarButtonItemStyleBordered withBlock:^(UIBarButtonItem *sender) {
[sender SH_removeAllBlocks];
[sender SH_addBlock:^(UIBarButtonItem *sender) {
SHBlockAssert(sender.SH_blocks.count == 1, @"Should have one block");
}];
}];
[button SH_addBlock:^(UIBarButtonItem *sender) {
}]
[button SH_addBlock:counterBlock];
[btnSecond SH_removeControlEventsForBlock:counterBlock];
[button SH_removeBlock:counterBlock];
[sender SH_removeAllBlocks];
// Unique blocks
[button SH_addBlock:blockOne];
[button SH_addBlock:blockTwo];
[button SH_addBlock:blockThree];
[button SH_addBlock:blockThree];
SHBlockAssert(button.SH_blocks.count == 3, @"Should have three blocks");
If you end up using SHBarButtonItemBlocks in a project, I'd love to hear about it.
email: [email protected]
twitter: @seivanheidari
SHBarButtonItemBlocks is © 2013 Seivan and may be freely
distributed under the MIT license.
See the LICENSE.md
file.