Skip to content

Instantly share code, notes, and snippets.

@jarsen
Created June 21, 2012 18:12
Show Gist options
  • Save jarsen/2967497 to your computer and use it in GitHub Desktop.
Save jarsen/2967497 to your computer and use it in GitHub Desktop.
Creating Custom UIBarButtonItems
// 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 setImage: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