Search code examples
iosswiftuitoolbar

How to change UIToolbar height?


I want to change the height of the UIToolbar in Navigation Controller, but I am not able to do so in swift with Xcode 7.3 and iOS 9. I have tried to set frame with CGRectMake at viewDidLoad, but it didn't work. Also tried to init a custom UIToolbar(), but the height remain the same.

Edit:

As per one of the answers, I have tried selected toolbar, press control and select the toolbar again, but what I got is shown in below screenshot instead:

Screenshot


Solution

  • You can use it with ; Change 45 for min or max heights.

    override func layoutSubviews() {
        super.layoutSubviews()
    
        var frame = self.bounds
        frame.size.height = 45
        self.frame = frame
    }
    
    override func sizeThatFits(size: CGSize) -> CGSize {
        var size = super.sizeThatFits(size)
        size.height = 45
        return size
    }
    

    Use it with like ;

    let navigationController = UINavigationController(navigationBarClass: nil, toolbarClass: Toolbar.self)
    

    Thanks