自定义高度的问题制作工具栏| Swift 5

自定义高度的问题制作工具栏| Swift 5,swift,toolbar,Swift,Toolbar,基本上,我有以下工具栏,当前设置为在左侧和右侧包含两个按钮: //Select All Toolbar self.navigationController?.isToolbarHidden = false self.navigationController?.toolbar.barTintColor = UIColor(named: "tabBarColor") //self.navigationController?.toolbar.barTintColor = UIColor.white s

基本上,我有以下工具栏,当前设置为在左侧和右侧包含两个按钮:

//Select All Toolbar
self.navigationController?.isToolbarHidden = false
self.navigationController?.toolbar.barTintColor = UIColor(named: "tabBarColor")
//self.navigationController?.toolbar.barTintColor = UIColor.white
self.navigationController?.toolbar.sizeToFit() // without this line it doesn't work
self.navigationController?.toolbar.tintColor = UIColor(named:"toolBarRedColor")
var items = [UIBarButtonItem]()

let selectbutton = UIBarButtonItem(title: "Left Button", style: .plain, target: self, action: #selector(printMe))

let unselectbutton = UIBarButtonItem(title: "Right Button", style: .plain, target: self, action: #selector(printMe))

items.append(selectbutton)
items.append( UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: self, action: nil))
items.append(unselectbutton)
self.toolbarItems = items
我想扩展工具栏的高度,并尝试执行以下操作:

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
    }

}
什么地方做得不对?高度没有调整

试试这个:

let navBarSize = CGSize(width: navigationController!.navigationBar.bounds.width, height: 200)

override func viewDidLayoutSubviews() {
    navigationController?.navigationBar.frame = CGRect(x: 0, y: 0, width: navBarSize.width, height: navBarSize.height)
}

希望这有帮助:)

这会去哪里?在自定义类中?尝试将其添加到显示导航栏的ViewController中。能否提供更多的代码?当我看不到整体结构时,这很难:)