I have an application where there are two items at the bottom bar in a view controller. One item is at the left and another one is at middle of the bottom bar. Now, what I like to do that when someone click on the middle item of the bottom bar, it will redirect the user to the website. how to get the action for the middle item of the bottom bar.
If this is a UIBarButtonItem, it has a target property and an action property, These configure what it does when tapped — it sends the action to the target. In theory, you should have configured these when you created the UIBarButtonItem.
Related
I am trying to add a logo to the very left side of my navigation bar. I still want to display the Back button and the title of the page, but the logo must be fixed to the left side before the Back button.
I tried adding the logo as a Bar Button Item, but this removes the Back button.
Is there any way to do this? Thanks in advance!
If you add a UIBarButtonItem as the leftBarButtonItem then you can also set the property
self.navigationItem.leftItemsSupplementBackButton = true
This will allow you to have two buttons without disrupting the back button. However it won't be on the far left, that space is reserved for the back button. If you want to go against Apple's design guidelines and the logo is more important the standard iOS navigation, you'll need to do something custom.
You could use the leftBarButtonItems property on UINavigationItem to set multiple items in your own order. One of those could be a logo and another a custom back button that you set to call navigationController.popViewControllerAnimated(true)
I have a Bar Button Item in the navigation bar of the view (Edit Button). Unlike other buttons (UIButton), I am unable to press ctrl and drag to view controller to create a function to handle it. I want when the button is pressed, a function body to execute.
How can I link them?
Just show the assistant editor
and use the document outline (the left bar that list all your view controllers and relative items) for select the bar button item, then CTRL & drag or drag with your right mouse button:
Automatically for bar button item Xcode link as action:
Make sure the button is selected (The view should darken a bit everywhere expect where the button is) and open up the Utilities area. Open the Connections inspector in utilities (an arrow pointing to the right) and under Triggered Segues drag from the circle to your code and create your action.
I'm modifying an app and this app has some buttons in its navigation bar, I wanted to add another button or Bar Button item by dragging it to the hierarchy but it seems I can't add it as a child to navigation bar, I wanted to ask if you have any solutions to this, here's a snapshot of the hierarchy of the storyboard, I want to add another Bar Button Item or another Button to the Navigation item.
Thanks
So I've just created a blank project and I can do this:
I've also done stuff like this before where I actually use a UIButton rather than a bar button item gaining some extra customisability. Just make sure that you set an outlet to the button and in the view controller call self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:self.customButton];:
You can have multiple right bar button items and if they overlap the title (if you have one) then they are essentially clipped. From my understanding, you can have as many buttons as you like until the space is gone (which can vary depending on the device, obviously). Relevant docs:
This array can contain 0 or more bar button items to display on the right side of the
navigation bar. Items are displayed right-to-left in the same order as they appear in the array. Thus, the first item in the array is the rightmost item and other items are added to the left of the previous item.
If there is not enough room to display all of the items in the array, those that would overlap the title view (if present) or the buttons on the left side of the bar are not
displayed.
An example with lots of buttons:
Programatically you can add buttons using:
navigationItem.rightBarButtonItems = [aButton, anotherButton, awesomeButton]
Just make sure you test that the smallest device you target will still provide a good UX for the user if you add lots of buttons.
here is the correct answer for swift :
let barButton_array: [UIBarButtonItem] = [Button1, Button2]
navigationItem.setRightBarButtonItems(barButton_array, animated: false)
Seems you can only have 3 elements on navigation bar with Interface Builder and you have to add more buttons via code. This link worked for me :
http://mandarapte.com/apple/add-navigation-bar-buttons-ios-app-xcode-project/
I am following a tutorial on Udemy about Navigation Controllers.
The instructions are to drag a Navigation Controller onto the storyboard, and then drag and drop a Bar Button Item on the right of its navigation bar to segue to another view controller.
However, when I drag the Bar Button Item to its would-be position on the navigation bar, no drop-zone gets highlighted, and the button gets added to a random tab at the bottom of the screen.
I have tried finding references to this problem but all solutions are programmatic and given the wysiwyg nature of iOS development I would like to solve it through XCode UI.
Is there some setup I must change or is this an XCode 7 discrepancy?
Try to add a ViewController and then in Editor -> Embed in -> NavigationController. Then it should work.
I have solved my problem by dragging the Bar Button Item into the Document Outline, below Root View Controller.
This automatically creates Left Bar Button Items and Right Bar Button Items, which gives you an opportunity to drag the Item in the section of the controller you like.
I'm pretty new to Xcode development (I'm using swift), and am building up my application flow in the storyboard. I'm attempting to create an "Add New" dialog in a similar style to that on the Calendar app.
In terms of structure, I have a UITableViewController that has a UINavigationItem on it (There is a UINavigationController before it in the storyboard. I have added a UIBarButtonItem with the Add Identifier, and created a Segue from it to a new UIViewController, using the "Present Modally" option to make the view appear in from the bottom.
On the "Add New" screen, I want to have a Navigation Bar at the top, with a Cancel Button, a Save Button and the page title (the same way the Calendar App Add Event view works).
Initially I figured I would just throw a UIToolBar item onto the page and create those items by hand. However, the apple standards seem to indicate that Toolbars should only ever appear at the bottom of the screen, not the top.
I can change the Segue to "Show", this causes the view to slide in from the right. It also sets the left hand button to a "Back" action (i.e. "
What is the apple-approved structure I should be using to do this? To summarise, I want to do the following:
Segue from the Add button on the List View to the Add View.
Animate the Add View in from the bottom
Display a Navigation Bar on the Add View containing three items:
Cancel (Far Left) - Returns to the Previous View (by sliding the view down)
Title (Middle)
Save (Far Right) - Performs a custom action (I can handle this myself)
You should present the "Add New" dialog inside another UINavigationController, even if you don't intent to push additional view controllers onto it once it is presented. This allows you to easily use navigation items again to show the buttons.