Skip to content

Instantly share code, notes, and snippets.

@romyilano
Forked from codeswimmer/ios_nav_bar_info_button.m
Created November 20, 2012 18:59
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 romyilano/4120194 to your computer and use it in GitHub Desktop.
Save romyilano/4120194 to your computer and use it in GitHub Desktop.
iOS: How to add an Info Button to the right button slot in a Navigation Bar
// This is assumed to be inside a UINavigationController
-(void)awakeFromNib
{
// How to turn a NavigationItem's rightBarButtonItem into an Info Button
// First, in your storyboard or xib add a Bar Button Item to the right slot in the navigation bar.
// Then, do this:
UIButton *infoLightButton = [UIButton buttonWithType:UIButtonTypeInfoLight];
infoLightButton.frame = CGRectMake(0.0, 0.0, 25.0, 25.0);
infoLightButton.backgroundColor = [UIColor clearColor];
[infoLightButton addTarget:self action:@selector(showInfo:) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *infoButton = [[UIBarButtonItem alloc] initWithCustomView:infoLightButton];
self.navigationItem.rightBarButtonItem = infoButton;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment