Latest 1.0.0
Homepage https://github.com/YoonLee/YLBarButtonActionCategory
License MIT
Platforms ios 5.0, requires ARC
Authors

YLBarButtonActionCategory

Original usage of the UIBarButtonItem needs action to be separated. Using this category to handle the action from UIBarButtonItem will make easy, lazy and simple one line of code!

Easy Installation

Using CocoaPods,

Create or Use Podfile file on your project folder then copy and paste below.

pod 'YLBarButtonAction', '~> 1.0.0'
// run for update on terminal
pod update

Methods

// default image initialization with action block
- (instancetype)initWithImage:(UIImage *)image style:(UIBarButtonItemStyle)style actionBlock:(void (^)(id))action;

// default title initialization with action block
- (instancetype)initWithTitle:(NSString *)title style:(UIBarButtonItemStyle)style actionBlock:(void (^)(id))action;

// default system button initialization with action block
- (instancetype)initWithBarButtonSystemItem:(UIBarButtonSystemItem)systemItem actionBlock:(void (^)(id))action;

Availability

iOS 4.0 +

Example

// import header
#import "UIBarButtonItem+Category.h"
UIImage *image1 = [UIImage imageWithName:@"img"];
UIBarButtonItem *buttonItem1 = [[UIBarButtonItem alloc] initWithImage:image1 
                                                                style:UIBarButtonItemStyleDone 
                                                          actionBlock:^(UIBarButtonItem *rb1) {
                                                          // action goes here
                                                         }

UIImage *image2 = [UIImage imageWithName:@"img2"];
UIBarButtonItem *buttonItem2 = [[UIBarButtonItem alloc] initWithImage:image2 
                                                                style:UIBarButtonItemStyleDone 
                                                          actionBlock:^(UIBarButtonItem *rb2) {
                                                          // action goes here
                                                         }

[self.navigationItem setRightBarButtonItems:@[buttonItem1, buttonItem2]];

// OR
// [self.navigationItem setRightBarButtonItem:buttonItem1];

Latest podspec

{
    "name": "YLBarButtonAction",
    "version": "1.0.0",
    "summary": "Category for having action with UIBarButtonItem",
    "description": "                   YLBarButtonAction is a category of UIBarButtonItem class that doesn't n                   need for having a separate method for action.n",
    "homepage": "https://github.com/YoonLee/YLBarButtonActionCategory",
    "license": {
        "type": "MIT",
        "file": "MIT_LICENSE"
    },
    "authors": {
        "Yoon Lee": "[email protected]"
    },
    "social_media_url": "http://twitter.com/whatyoonsays",
    "platforms": {
        "ios": "5.0"
    },
    "source": {
        "git": "https://github.com/YoonLee/YLBarButtonActionCategory.git",
        "tag": "1.0.0"
    },
    "source_files": [
        "YLBarButtonAction",
        "YLBarButtonAction/**/*.{h,m}"
    ],
    "exclude_files": "Classes/Exclude",
    "requires_arc": true
}

Pin It on Pinterest

Share This