How to make a toolbar visible all the time in Swift? - ios

I made a toolbar at the bottom of the tableview.
But when I launch the simulator, the toolbar only becomes visible when I scroll all the way down to the bottom. How can I make toolbar visible all the time?

If you're using a Navigation Controller, make sure to tick "Shows Toolbar" and add the buttons there, not on a standalone toolbar.
In order to show only on some, you'll need 2 different views, one that will hide it and another that won't and add the following to the respective view's viewWillAppear:
self.navigationController.toolbarHidden = YES;
(Set to YES to hide, NO to show)
You can play around with the Simulated Metrics on the Storyboard so as to visually simulate the run-time effect by setting Bottom Bar to either None or Toolbar instead of inferred, as appropriated.

Use below line : self.navigationController.toolbarHidden = false
In viewDidAppear() so that Everytime when your this viewcontroller appears your toolbar will become visible.

Related

Bottom layout guide prevents interaction with the uitoolbar which is exchanged with the uitabbar

I am trying to make it possible to exchange the tab bar with the tool bar on iOS when the UITableView enters the editing mode.
However, when I set the
func updateBottomBar() {
tabBarController?.tabBar.isHidden = isInEditMode
actionToolBar.isHidden = !isInEditMode
}
, everything displays correct, however I can not interact with the toolbar. It seems like it is under the bottom layout guide, and the touches cant pass through. I tried bumping the toolbar.layer.zposition to 100, didnt work.
Note: if I programatically reposition the ToolBar to be a little bit higher, then exactly the portion of the ToolBar which is above the top of now hidden TabBar will be okay to interact with. Say i put the ToolBar 20points higher, then the 20 top points of the ToolBar allow me to press the buttons, and the bottom part doesn't allow.
I have:
extended edges under bottom bar disabled
Hides bottom bar on push disabled
user interaction enabled
right now. Changing those didn't give any success.
One possible issue could be your userInteraction of your custom tabbar being set to false.
You can do that directly in the your storyboard by opening the attribute inspector on your ActionToolBar
Also, to confirm you don't have any invisible view on top of your custom toolbar, you can use debug the view hierarchy when running on your simulator:

Ios Swift : Adding or Moving NavigationBar to bottom of the view controller

I want to move the navigation controller bar to the bottom of the view controller. How can i get this done ?
I tried :
self.navigationController!.navigationBar.frame = CGRectMake(
0,
UIScreen.mainScreen().bounds.height - 50,
UIScreen.mainScreen().bounds.width,
50)
This is moving to the bottom but hiding all other controller objects and also back button is not woking.
Sujay U N,
You should not try to move the UINavigationBar provided by the embeded UINavigationController to the bottom of the screen. Trying that will obvisoulsy move all the view's below it causing all the controller objects to hide.
Workaround
Approach 1:
Consider using ToolBar :)
Toolbar is designed to be placed at the bottom of the screen. If you are using xib or storyboard you can pick toolbar from components library and place it on your ViewController's bottom and then apply autoresizing masks or constraints properly :)
Now in order to show the back button make use of UIBarButtonItems. Change the style to custom and provide it arrow image or provide default style as done.
Though now you are all set to go :) You will notice UINavigationBar at the top of your view controller. In order to get rid of it,
select your ViewController, select its TopBar property set it to none :)
Approach 2
Use UINavigationBar.
Specific about using Navigation bar and dont want to use toolbar, well you can do the same thing with UINavigationBar as well.
Drag the UINavigationBar from components library place it at the bottom of the screen. Drag the UIBarButtonItem drop it as leftBarButtonItem, change the barButtonItem image to your back image. ( Same process as UIToolBar just use UINavigationBar instead)
Understand this is not same as the navigation bar provided by the embeded NavigationController. So get rid of NavigationBar at the top of your ViewController same as I explained above here as well
Finally,
In both the cases, draw an IBoutlet from barbutton item and handle poping the viewController programmatically.
Happy coding :)

Bar Button Item is not Showing

I am trying to create a bottom toolbar. So I dragged I Bar Button Item to the View Controller and it was automatically position at the bottom, see image below:
But when I run the app, it doesn't show the bar at the bottom.
I already added:self.navigationController?.navigationBarHidden = false
I think it's just only a constraints problem.
First of all check your Document Outline near to the left of your table, to see the position (toolbar is just below table):
Add your constraints and pay attention to all options as shown in the picture:
Then, take a look to the size inspector, for the table view:
And for the toolbar:
This configuration working both in portrait/landscape mode.
Drag UIToolbar controller directly instead of only UIBarbutton item.
self.navigationController?.navigationBar.hidden=false
Have you set constraints of UIToolbar? I just guess it can be one of the reasons why you cannot see your barbuttoitem.
The navigation bar and the toolbar are two different things and the toolbar is hidden by default. Try setting the toolbar hidden attribute to false.
Sometimes bar button item and bar button do not show when we present our screen. On screen we can then not see bar button item and bar button. So we need to push our screen if we want bar button item and rightBarButtonItem.

Using Autolayout, unable to move the navigation bar down 20px

I have a UITabBarController which has four tabs. One of those tabs opens a my results screen (a UITableViewController).
On showing this screen, I want to move the UINavigationBar down 20px (to make room for a custom UIStatusBar which I show on all screens).
On all my other screens, I add some code to the viewWillAppear method to change the self.navigationController.navigationBar.frame.origin.y to 20.
but these are all "non-root" screens (i.e. a pushed view with a back button).
However on THIS screen the UINavigationBar must be initially visible, even though it is the root view. I use the same code, but it doesn't move the view down.
I'm assuming autolayout is moving it back into position, so I tried adding this code into viewWillLayoutSubviews and viewDidLayoutSubviews. But when I do this the navigationbar doesn't move down until the first time the tableview is scrolled.
What do I need to do to force the navigationBar to move down (and stay down) before the screen appears?
Are you using storyboards? Set the Y in storyboards to 20, Make your viewcontroller implement UINavigation bar, then add this code:
-(UIBarPosition)positionForBar:(id<UIBarPositioning>)bar{
return UIBarPositionTopAttached;
}
This will tell the app that the navigation bar is to be attached, it will remain at 20px but extend the background all the way up.. So essentially it'll look like it's at y = 20.

Animate Controls down with change to UINavigationBar

I have a UINavigationController with standard UINavigationBar. When presenting certain UIViewControllers and orientations, the UINavigationBar may or may not appear and it may or may not have a prompt element. This means that the bar height changes frequently.
I have some subviews below the UINavigationBar set with NSLayoutConstraints to topLayoutGuide. It generally lays out as expected, adjusting vertical position of the subviews appropriately based on the height of the UINavigationBar. What it does not do is move the subviews at times when the UINavigationBar is animated after the view is already displayed.
Specifically, coming from a state with UINavigationBar hidden, transition to a UIViewController which does not hide the navigation bar to one which does. The view displays, then navigation bar animates into place. The subviews do not move down. If I rotate the device, every things lays out appropriately again. Only when animating the navigation bar in and out or to display/hide the prompt I not find a hook to reevaluate the constraints.
I tried [self.view updateConstraints] and [self.view updateConstraintsIfNeeded] in various places such as viewDidAppear, viewDidLayoutSubviews. Nothing seems to update that topLayoutConstraint.
I am familiar with edge restraints, translucent navigation bar and other various methods of keeping the entire view from appearing under the navigation bar. I do want to keep view full size and I want the translucent bar so these are not solutions for me. It seems the constraints should handle this automatically, hence the "auto" in auto layout.
To simplify, for recreation, UINavigationController with rootViewcontroller showing normal navigation bar with just a title. In viewDidLoad of the next presented viewController I have [self.navigationContoller setPrompt:self.myPrompt]. The view is presented, when the prompt is set, the navigation bar grows larger. Some labels below the bar are set with relation to topLayoutGuide, which places them correctly initially. I expect they would move down when the bar grows. Rotate device back and forth, they now layout correctly. Pop the viewController and push back to top, repeats as above.
So, it turns out it was all me. After trying all manner of forcing layout updates in all sorts of ways, the solution was to move the [myView setPrompt:myPrompt] out of viewDidLoad and call it in viewDidAppear instead.
Works completely as expected. Navbar grows, subviews shift and shrink as needed. Now I have to hunt down all the experimental code I plastered everywhere trying to do it wrong.

Resources