swift - 使用自定义高度制作工具栏 | 斯威夫特 5
问题描述
本质上,我有以下工具栏,当前设置为在左侧和右侧包含两个按钮:
//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)
}
希望这可以帮助 :)
推荐阅读
- java - 基于反应器中条件检查的异步顺序调用
- vb.net - 如何删除datagirdview中的所有空行?
- python-3.x - 使用 Sklearn 的 CountVectorizer 查找多个不按顺序排列的字符串
- java - 蒙特卡洛模拟预测总统选举
- reactjs - Webpack 4:模块解析失败:意外的令牌
- android - 协调器布局并在工具栏折叠时显示文本
- docker - msys2 和 docker run 指定命令:在 docker 中运行之前在本地查找命令
- javascript - localstorage 将值发送到 iframe 中的文件
- python-3.x - 在 Python 中以编程方式执行用户输入的 pdb 或 ipdb 命令
- wordpress - 如何将新的可排序日期元添加到自定义帖子类型