Skip to content

Instantly share code, notes, and snippets.

@codeswimmer
Created February 7, 2012 04:58
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save codeswimmer/1757294 to your computer and use it in GitHub Desktop.
Save codeswimmer/1757294 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