SHBarButtonItemBlocks 1.2.1

SHBarButtonItemBlocks 1.2.1

TestsTested
LangLanguage Obj-CObjective C
License MIT
ReleasedLast Release Dec 2014

Maintained by Seivan Heidari.



  • By
  • Seivan Heidari

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.

Overview

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(™)

API

Init

Creating

Removing

Helpers and Properties

USAGE

Init

Creating

Removing

Helpers and Properties

Installation

pod 'SHBarButtonItemBlocks'

Setup

Put this either in specific files or your project prefix file

#import "UIBarButtonItem+SHBarButtonItemBlocks.h"

or

#import "SHBarButtonItemBlocks.h"

API

Init

#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;

Creating

#pragma mark -
#pragma mark Add
-(void)SH_addBlock:(SHBarButtonItemBlock)theBlock;

Removing

#pragma mark -
#pragma mark Remove
-(void)SH_removeBlock:(SHBarButtonItemBlock)theBlock;
-(void)SH_removeAllBlocks;

Helpers and Properties

#pragma mark -
#pragma mark Properties

#pragma mark -
#pragma mark Getters
@property(nonatomic,readonly) NSSet * SH_blocks;

Usage

Init

Class convenience selectors for creating directly.

  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");
    }];
  }];

Creating

With SHBarButtonItemBlocks you can set auto-removed blocks instead of using selectors

  [button SH_addBlock:^(UIBarButtonItem *sender) {

  }]

or if you want add additional blocks

  [button SH_addBlock:counterBlock];

Removing

Remove specific blocks - will also remove the Event from the target if it was the last block

  [btnSecond SH_removeControlEventsForBlock:counterBlock];

Remove specific blockss

      [button SH_removeBlock:counterBlock];

Remove all blocks

    [sender SH_removeAllBlocks];

Helpers and Properties


    // 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");

Contact

If you end up using SHBarButtonItemBlocks in a project, I'd love to hear about it.

email: [email protected]
twitter: @seivanheidari

License

SHBarButtonItemBlocks is © 2013 Seivan and may be freely distributed under the MIT license. See the LICENSE.md file.