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

12,645

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 :)

enter image description here

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. enter image description here

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 :) enter image description here

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)

enter image description here

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 :)

Share:
12,645
Sujay U N
Author by

Sujay U N

If ( YouDoNotKnwMe ) { String Name = “Sujay U N” String Mobile = 9964120147 String EMail = "[email protected]" If ( YouLykToKnwMorAbtMe ) { String VisitWebsite = www.sujayun.cf String FacebookPage = https://www.facebook.com/dijisuji String TwitterPage = https://twitter.com/sujayun String LinkedinPage = https://in.linkedin.com/in/sujayun String StackoverflowPage = https://stackoverflow.com/users/5078763/sujay-u-n String GitlabPage = https://gitlab.com/dijisuji String GithubPage = https://github.com/sujayun } }

Updated on June 04, 2022

Comments

  • Sujay U N
    Sujay U N over 1 year

    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.