Created
February 3, 2012 10:55
-
-
Save rscarvalho/1729653 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NSMutableArray* buttons = [NSMutableArray arrayWithCapacity:2]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// define a "container" button | |
self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithCustomView:toolbar] autorelease]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (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