Created
August 14, 2011 15:47
-
-
Save darkseed/1145005 to your computer and use it in GitHub Desktop.
Multiple buttons UINavigation
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 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