Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add several UIBarButtonItems to a NavigationBar?

I want to draw multiple buttons on a UINavigationBar. These will be either on right side or left side.

like image 687
Khalid Usman Avatar asked Dec 08 '11 13:12

Khalid Usman


People also ask

How do I add a bar button to the navigation bar?

To do this press cmd, shift and l, and then search for bar button item: Once you have found the bar button item drag it into the navigation bar, make sure to add one to the left and the right hand sides: Now that we have are bar button items in the navigation bar, we create actions in our code.

How can I customize the appearance of buttons in uinavigationitem?

However, you can customize the appearance of buttons by sending the setter messages to UIBarButtonItemAppearance to customize all buttons, or to a specific UIBarButtonItem instance. You can use customized buttons in standard places in a UINavigationItem object ( backBarButtonItem, leftBarButtonItem, rightBarButtonItem) or a UIToolbar instance.

How to right-align navigation bar buttons in Bootstrap?

The .navbar-right class is used to right-align navigation bar buttons. In the following example we insert a "Sign Up" button and a "Login" button to the right in the navigation bar. We also add a glyphicon on each of the two new buttons: To add buttons inside the navbar, add the .navbar-btn class on a Bootstrap button:

Can the navigation bar be fixed at the top or bottom?

The navigation bar can also be fixed at the top or at the bottom of the page. A fixed navigation bar stays visible in a fixed position (top or bottom) independent of the page scroll. The .navbar-fixed-top class makes the navigation bar fixed at the top:


1 Answers

I did one example in which I had two buttons ( i.e. Edit and +) on Right side of NaviagationBar.

1) You have to create one NSMutableArray(i.e. "buttons" in example) and add UIBarButtonItem (i.e. bi1 and bi2 in example) to the NSMutableArray (i.e. buttons).

2) Add NSMutableArray(i.e. buttons in example) to toolbar(i.e. UIToolbar *tools in example).

3) Add toolbar to NavigationBar.

 NSMutableArray *buttons = [[NSMutableArray alloc] initWithCapacity:2];
 UIToolbar *tools = [[UIToolbar alloc]
                    initWithFrame:CGRectMake(0.0f, 0.0f, 90.0f, 55.01f)];
// Add bar button1.

UIBarButtonItem *bi1 = [[UIBarButtonItem alloc] initWithTitle:@"Edit" style:UIBarButtonItemStylePlain target:self action:@selector(Edit:)];
bi1.style = UIBarButtonItemStyleBordered;
bi1.width = 45;
[buttons addObject:bi1];
//[bi1 release]; Do not release if ARC enabled.

// Add bar button2.
UIBarButtonItem *bi2 = [[UIBarButtonItem alloc] initWithTitle:@"+" style:UIBarButtonItemStylePlain target:self action:@selector(Add:)];
bi2.style = UIBarButtonItemStyleBordered;
[buttons addObject:bi2];
//[bi2 release]; Do not release if ARC enabled.

// Add buttons to toolbar and toolbar to nav bar.
[tools setItems:buttons animated:NO];
//[buttons release];  Do not release if ARC enabled.

 // Add toolbar to nav bar.
UIBarButtonItem *twoButtons = [[UIBarButtonItem alloc] initWithCustomView:tools];
[tools release];
self.navigationItem.rightBarButtonItem = twoButtons;
//[twoButtons release]; Do not release if ARC enabled.
like image 161
rohan-patel Avatar answered Oct 13 '22 10:10

rohan-patel