Выпуск панели инструментов с пользовательской высотой | Swift 5 - PullRequest
0 голосов
/ 23 января 2020

По сути, у меня есть следующая панель инструментов, которая в настоящее время настроена на две кнопки с левой и правой стороны:

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

}

Что делается неправильно? Высота не регулируется.

1 Ответ

0 голосов
/ 23 января 2020

Попробуйте:

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

Надеюсь, это поможет:)

...