所以我在观看 WWDC 2015 的视频,其中演示者展示了一个底部有固定栏的表格 View ,他在其中放置了一个进度条和一些标签。视频是关于点播资源的,所以他没有详细说吧是怎么实现的。但我真的很想知道它是如何实现的:
View 的 Controller 是 UITableViewController 的子类,因此该 Controller 的 Root View 必须是 TableView 。据我所知,没有干净的方法来修复 TableView 中的某些 UI View 。
它看起来也不像导航 Controller 中的工具栏,因为标签位于中心并且进度条横跨整个栏。我认为您只能在工具栏内放置离散按钮?也许不是这样,但从那个 TableView Controller 的大小来看,他似乎没有写太多代码来实现它。
我想知道这个底栏是如何实现的?可以看看at this moment of the video .
(我想知道在这里粘贴WWDC视频截图是否合法?)
最佳答案
实际上,它看起来很像使用导航 Controller 提供的工具栏。
您可以将自定义 View 添加到工具栏,并且可以使用灵活的空间项目将项目居中。以下是如何在短短几行中做到这一点:
// In your tabble view controller subclass
override func viewDidLoad()
{
super.viewDidLoad()
// ...
let label = UILabel(frame: CGRect(x: 0.0, y: 0.0, width: UIScreen.main.bounds.size.width, height: 44.0))
label.textAlignment = .center
label.text = "Hello world!"
let toolBarItem = UIBarButtonItem(customView: label)
let flexibleSpace = UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: nil, action: nil)
self.setToolbarItems([flexibleSpace, toolBarItem, flexibleSpace], animated: false)
self.navigationController?.isToolbarHidden = false
let progressView = UIProgressView(progressViewStyle: .bar)
progressView.frame = CGRect(x: 0.0, y: 0.0, width: UIScreen.main.bounds.size.width, height: 2.0)
progressView.trackTintColor = .lightGray
progressView.progress = 0.5
self.navigationController?.toolbar.addSubview(progressView)
}
关于ios - UITableView 上的这个固定底栏是如何实现的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42734809/