具有自定义高度的问题制作工具栏|雨燕5

问题描述 投票:0回答:1

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

//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
    }

}

做错了什么?高度未调整。

swift toolbar
1个回答
0
投票

尝试一下:

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

希望这会有所帮助:)

© www.soinside.com 2019 - 2024. All rights reserved.