Skip to content

Instantly share code, notes, and snippets.

@patelrohan
Created December 30, 2011 07:18
Show Gist options
  • Save patelrohan/1538443 to your computer and use it in GitHub Desktop.
Save patelrohan/1538443 to your computer and use it in GitHub Desktop.
Add buttons to UInavigationbar
UIToolbar *tools = [[UIToolbar alloc]
initWithFrame:CGRectMake(0.0f, 0.0f, 90.0f, 45.01f)]; // 44.01 shifts it up 1px
tools.clearsContextBeforeDrawing = NO;
tools.clipsToBounds = NO;
tools.barStyle = -1;
NSMutableArray *buttons = [[NSMutableArray alloc] initWithCapacity:2];
// ---------------------------------------Add Pin button----------------------------------.
UIBarButtonItem *bi = [[UIBarButtonItem alloc] initWithTitle:@"Pin" style:UIBarButtonItemStylePlain target:self action:@selector(PinClicked)];
bi.style = UIBarButtonItemStyleBordered;
UIImage *img = [UIImage imageNamed:@"purple-circle32.png"];
[bi setImage:img];
//bi1.width = 45;
[buttons addObject:bi];
[bi release];
// --------------------------------Add Hot Spot button----------------------------------.
bi = [[UIBarButtonItem alloc] initWithTitle:@"Hotspot" style:UIBarButtonItemStylePlain target:self action:nil];
bi.style = UIBarButtonItemStyleBordered;
// img = [UIImage imageNamed:@"purple-circle32.png"];
// [bi setImage:img];
[buttons addObject:bi];
[bi release];
// Add buttons to toolbar and toolbar to nav bar.
[tools setItems:buttons animated:NO];
[buttons release];
UIBarButtonItem *twoButtons = [[UIBarButtonItem alloc] initWithCustomView:tools];
[tools release];
self.navigationItem.rightBarButtonItem = twoButtons;
[twoButtons release];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment