Skip to content

Instantly share code, notes, and snippets.

@pyanfield
Created March 20, 2014 03:40
Show Gist options
  • Save pyanfield/9656732 to your computer and use it in GitHub Desktop.
Save pyanfield/9656732 to your computer and use it in GitHub Desktop.
display original image on UIBarButtonItem
// ios 7 or later
UIImage *icon = [[UIImage imageNamed:@"icon"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
UIBarButtonItem *iconItem = [[UIBarButtonItem alloc] initWithImage:icon style:UIBarButtonItemStylePlain target:self action:@selector(iconEvent)];
// before ios 6
UIImage *icon = [UIImage imageNamed:@"icon"];
UIButton *iconBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[iconBtn addTarget:self action:@selector(iconEvent) forControlEvents:UIControlEventTouchUpInside];
iconBtn.bounds = CGRectMake( 0, 0, icon.size.width, icon.size.height );
[iconBtn setImage:icon forState:UIControlStateNormal];
UIBarButtonItem *iconItem = [[UIBarButtonItem alloc] initWithCustomView:iconBtn];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment