Add multiple UIBarButtonItem in the NavigationController navigation bar

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.