Skip to content

Instantly share code, notes, and snippets.

@tiagobbraga
Forked from jarsen/UIBarButtonItem+Custom.m
Last active December 16, 2015 05:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tiagobbraga/5385130 to your computer and use it in GitHub Desktop.
Save tiagobbraga/5385130 to your computer and use it in GitHub Desktop.
// UIBarButtonItem+Custom.h
// Created by Jason Larsen on 6/21/12.
#import <UIKit/UIKit.h>
@interface UIBarButtonItem (Custom)
- (void)customViewButtonWithImage:(NSString *)imageName target:(id)target action:(SEL)selector;
@end
// UIBarButtonItem+Custom.m
// Created by Jason Larsen on 6/21/12.
#import "UIBarButtonItem+Custom.h"
@implementation UIBarButtonItem (Custom)
- (void)customViewButtonWithImage:(NSString *)imageName target:(id)target action:(SEL)selector
{
UIImage *image = [UIImage imageNamed:imageName];
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(0, 0, image.size.width, image.size.height);
[button setBackgroundImage:image forState:UIControlStateNormal];
button.showsTouchWhenHighlighted = YES;
[button addTarget:target action:selector forControlEvents:UIControlEventTouchUpInside];
self.customView = button;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment