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:
It is the following
With properties like this:
And like this:
Hope it helps.
Related Topics
Retain Cycle (Strong Reference) Fix for Custom Uitextfield
iOS Safari Memory Usage with "-Webkit-Transform"
How to Cache or Preload Sklabelnode Font
Xcode6: Run Two Instances of the Simulator
How to Get the Height and Width of an Uiimage
How to Change the Color of the Text in a Uipickerview Under iOS 7
Storyboards VS. the Old Xib Way
How to Use Static Cells in Uitableview Without Using Storyboards
Google Maps iOS Sdk, Getting Current Location of User
Getter VS Computed Property. What Would Warrant Using One of These Approaches Over the Other
CSS Gradient Not Working on iOS
How to Post Nested JSON by Swiftyjson and Alamofire
iOS Autolayout: Two Buttons of Equal Width, Side by Side
iOS Scrollview Needs Constraint for Y Position or Height
How to Dismiss Keyboard iOS Programmatically When Pressing Return