How to Add 2 Buttons into the Uinavigationbar on the Right Side Without Ib

How to add multiple UIBarButtonItems on right side of Navigation Bar?

Use this in swift:

override func viewDidLoad() {
super.viewDidLoad()

let editImage = UIImage(named: "plus")!
let searchImage = UIImage(named: "search")!

let editButton = UIBarButtonItem(image: editImage, style: .Plain, target: self, action: "didTapEditButton:")
let searchButton = UIBarButtonItem(image: searchImage, style: .Plain, target: self, action: "didTapSearchButton:")

navigationItem.rightBarButtonItems = [editButton, searchButton]
}

Write the action functions like this:

func didTapEditButton(sender: AnyObject){
...
}

func didTapSearchButton(sender: AnyObject){
...
}

Swift 4 & 5

    override func viewDidLoad() {
super.viewDidLoad()
let editImage = UIImage(named: "edit")!
let searchImage = UIImage(named: "search")!

let editButton = UIBarButtonItem(image: editImage, style: .plain, target: self, action: #selector(didTapEditButton(sender:)))
let searchButton = UIBarButtonItem(image: searchImage, style: .plain, target: self, action: #selector(didTapSearchButton(sender:)))

navigationItem.rightBarButtonItems = [editButton, searchButton]
}

@objc func didTapEditButton(sender: AnyObject){

}

@objc func didTapSearchButton(sender: AnyObject){

}

Add more then one button in top navigation bar in iOS

UINavigationItem Class Reference having property of leftBarButtonItems and rightBarButtonItems so you can add multiple UIBarButtonItem in your navigation control using following example code:

 UIBarButtonItem *FirstButton = [[UIBarButtonItem alloc] 
initWithTitle:@"First"
style:UIBarButtonItemStyleBordered
target:self
action:@selector(AcionFirst:)];

UIBarButtonItem *secondButton = [[UIBarButtonItem alloc]
initWithTitle:@"Second"
style:UIBarButtonItemStyleBordered
target:self
action:@selector(AcionSecond:)];

self.navigationItem.leftBarButtonItems= [NSArray arrayWithObjects:FirstButton,secondButton,nil];

-(void)AcionFirst:(id)sender
{
//do something for first bar button

}

-(void)AcionSecond:(id)sender
{
//do something for second bar button
}

Can I add two right-hand buttons to a UINavigationBar?

There's no way to do this using all native graphics. However, if you're willing to get your hands a little dirty in Acorn or Photoshop, you can create your buttons images there, and then add several buttons to a UIView, encase that in a UIBarBUttonItem, and set it to be the leftBarButtonItem.

This question tackles the item as well: How to add 2 buttons into the UINavigationbar on the right side without IB?

iOS - UINavigationController adding multiple right items?

I am sure I read in the developer reference that additional buttons in the navigation bar is frowned upon. I cannot find that passage now. I have not done it myself, but found this link that seems to outline exactly what you need to do: (http://www.mattdipasquale.com/blog/2010/11/02/how-to-add-multiple-uibarbuttonitems-to-uinavigationbar/)

Have you considered using the toolbar property of the navigation controller?

Adding buttons to navigation bar ios

self.navigationItem.rightBarButtonItems = navItemsArray;

works only in iOS 5.

Add goBack and goForward to the right of the Navigation Bar

I did it in the past, it's easy:

myBackBarButton = [[UIBarButtonItem alloc] initWithImage:barButtonImage
style:UIBarButtonItemStylePlain
target:myWebView
action:@selector(goBack)];

myForwardButtom = [[UIBarButtonItem alloc] initWithImage:anotherBarButtonImage
style:UIBarButtonItemStylePlain
target:myWebView
action:@selector(goForward)];

Where myWebView is your UIWebView (In case it's your class, use self)

If your buttons are already created, then just add the target and the action to them:

myBackButton.target = myWebView;
myBackButton.action = @selector(goBack);

What you are doing is adding the action goForward: and goBack: of the target that is your webview, to those buttons.

Add borderless search buttons in UINavigationbar

I think you have a bar button item. I have played around with it. And the Bar Buttom Item has to have a Tint of Clear Color. The actual Button a Type of Custom. Then it comes out more the way you want it (I think).

In my IB it looks like this:

Sample Image

It is the following

Sample Image

With properties like this:

Sample Image

And like this:

Sample Image

Hope it helps.



Related Topics



Leave a reply



Submit