Add multiple UIBarButtonItem in the NavigationController navigation bar
In actual development, the navigator is one of the most important containers. We often need to add various style buttons in the navigation bar. It is very easy to add a button. The Code is as follows:
UIBarButtonItem * anotherButton = [[UIBarButtonItem alloc] initWithTitle: @ "Setting" style: UITabBarSystemItemContacts
Target: self action: @ selector (clickSettings :)];
Self. navigationItem. rightBarButtonItem = anotherButton;
[AnotherButton release];
The button style can have a variety of specific can refer to: https://developer.apple.com/library/ios/prerelease/#documentation/UIKit/Reference/UIBarButtonItem_Class/
In some projects, you need to add two buttons on the right to implement the following styles:
UIToolbar * tools = [[UIToolbar alloc] initWithFrame: CGRectMake (0, 0,150, 45)];
[Tools setTintColor: [self. navigationController. navigationBar tintColor];
[Tools setAlpha: [self. navigationController. navigationBar alpha];
NSMutableArray * buttons = [[NSMutableArray alloc] initWithCapacity: 2];
UIBarButtonItem * anotherButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem: UIBarButtonSystemItemAdd
Target: self action: @ selector (clickSettings :)];
UIBarButtonItem * anotherButton1 = [[UIBarButtonItem alloc] initWithTitle: @ "Edit" style: UITabBarSystemItemContacts
Target: self action: @ selector (clickEdit :)];
[Buttons addObject: anotherButton];
[AnotherButton release];
[Buttons addObject: anotherButton1];
[AnotherButton1 release];
[Tools setItems: buttons animated: NO];
[Buttons release];
UIBarButtonItem * myBtn = [[UIBarButtonItem alloc] initWithCustomView: tools];
Self. navigationItem. rightBarButtonItem = myBtn;
[MyBtn release];
[Tools release];
From computer learning village