Skip to content

Instantly share code, notes, and snippets.

@darkseed
Created August 14, 2011 15:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save darkseed/1145005 to your computer and use it in GitHub Desktop.
Save darkseed/1145005 to your computer and use it in GitHub Desktop.
Multiple buttons UINavigation
// Create the toobar
UIToolbar* toolbar = [[UIToolbar alloc]
initWithFrame:CGRectMake(0, 0, 100, 45)];
[toolbar setBarStyle: UIBarStyleDefault];
// Create and array for the buttons
NSMutableArray* buttons = [[NSMutableArray alloc] initWithCapacity:3];
// Create a "+" button
UIBarButtonItem *addButton = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemAdd
target:self
action:@selector(addAction:)];
addButton.style = UIBarButtonItemStyleBordered;
[buttons addObject:addButton];
[addButton release];
// Create a spacer between them
UIBarButtonItem *spacer = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace
target:nil
action:nil];
[buttons addObject:spacer];
[spacer release];
// Create an "Edit" button
UIBarButtonItem *editButton = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemEdit
target:self
action:@selector(editAction:)];
editButton.style = UIBarButtonItemStyleBordered;
[buttons addObject:editButton];
[editButton release];
// Add the buttons to the toolbar and release them
[toolbar setItems:buttons animated:NO];
[buttons release];
// Add the toolbar to the NavigationBar
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]
initWithCustomView:toolbar];
[toolbar release];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment