Skip to content

Instantly share code, notes, and snippets.

@rscarvalho
Created February 3, 2012 10:55
Show Gist options
  • Save rscarvalho/1729653 to your computer and use it in GitHub Desktop.
Save rscarvalho/1729653 to your computer and use it in GitHub Desktop.
NSMutableArray* buttons = [NSMutableArray arrayWithCapacity:2];
// Add items to the array
UIBarButtonItem* bi;
bi = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd
target:self
action:@selector(barButtonClicked:)];
[buttons addObject:bi];
[bi release];
bi = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCamera
target:self
action:@selector(barButtonClicked:)];
[buttons addObject:bi];
[bi release];
// Create a Flexible Space to right align the buttons
bi = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace
target:nil action:nil];
[buttons insertObject:bi atIndex:0];
[bi release];
// Create and configure the toolbar, with the items array
UIToolbar *toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 103, 44.01)];
toolbar.autoresizingMask = UIViewAutoresizingFlexibleHeight;
toolbar.clearsContextBeforeDrawing = NO;
toolbar.tintColor = self.navigationController.navigationBar.tintColor;
toolbar.barStyle = -1; // Limpa o background
[toolbar setItems:buttons animated:NO];
// define a "container" button
self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithCustomView:toolbar] autorelease];
- (void)setupNavigationItems
{
NSMutableArray* buttons = [NSMutableArray arrayWithCapacity:2];
// Add items to the array
UIBarButtonItem* bi;
bi = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd
target:self
action:@selector(barButtonClicked:)];
[buttons addObject:bi];
[bi release];
bi = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCamera
target:self
action:@selector(barButtonClicked:)];
[buttons addObject:bi];
[bi release];
// Create a Flexible Space to right align the buttons
bi = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace
target:nil action:nil];
[buttons insertObject:bi atIndex:0];
[bi release];
// Create and configure the toolbar, with the items array
UIToolbar *toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 103, 44.01)];
toolbar.autoresizingMask = UIViewAutoresizingFlexibleHeight;
toolbar.clearsContextBeforeDrawing = NO;
toolbar.tintColor = self.navigationController.navigationBar.tintColor;
toolbar.barStyle = -1; // Limpa o background
[toolbar setItems:buttons animated:NO];
// define a "container" button
self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithCustomView:toolbar] autorelease];
// This button was added so you can compare the "native" button and the toolbar buttons
self.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc] initWithTitle:@"Some Title"
style:UIBarButtonItemStyleBordered
target:self
action:@selector(barButtonClicked:)] autorelease];
[toolbar release];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment