public
Created

Multiple buttons UINavigation

  • Download Gist
gistfile1.m
Objective-C
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
// 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];

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.