Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Navigation Controller Toolbar Size & Location - iOS Swift

Hello I am currently working on an application in Swift 3. I am having problems in a table view controller which is embedded in a navigation controller. I am currently displaying the navigationController toolbar. However on the initial table view controller I set the navigation bar to hidden. This results in the toolbar being resized and relocated.

Does anyone know how I can reload the toolbar to follow the following line of code: (This is called in view will appear)

self.navigationController?.toolbar.frame = CGRect(x: 0, y: UIScreen.main.bounds.height-80, width: self.view.frame.size.width, height: 80)

I cannot find out how to resize the toolbar after hiding the navigation bar using the following: (This is called in view did appear)

self.navigationController?.setNavigationBarHidden(true, animated: true)
like image 290
Jerland2 Avatar asked Nov 20 '25 08:11

Jerland2


1 Answers

You could not resize your toolbar directly:

But you can inherit UIToolbar in your project:

import UIKit

class CustomToolbar: UIToolbar {

override func sizeThatFits(_ size: CGSize) -> CGSize {

    var newSize: CGSize = super.sizeThatFits(size)
    newSize.height = 80  // there to set your toolbar height 

    return newSize
    }

}

In the storyboard:

toolbar's class set to CustomToolbar

The result, height of toolbar is 80:

the height is 80 now

like image 147
aircraft Avatar answered Nov 22 '25 21:11

aircraft



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!