我正在使用Swift 3,Xcode 8.2。Swift - 自定义视图以显示空表格单元
我已经能够创建一个标签来覆盖空表格视图单元格,当没有显示。
我的代码如下,它位于UITableViewController
的子类中。
override func numberOfSections(in tableView: UITableView) -> Int {
// if there are scans to display...
if items.count > 0 {
tableView.backgroundView = nil
tableView.separatorStyle = .singleLine
return 1
}
else { // otherwise, return 0, remove cell lines, and display a Label
let rect = CGRect(x: 0,
y: 0,
width: tableView.bounds.size.width,
height: tableView.bounds.size.height)
let noScanLabel: UILabel = UILabel(frame: rect)
noScanLabel.text = "No Scans"
noScanLabel.textColor = UIColor.gray
noScanLabel.font = UIFont.boldSystemFont(ofSize: 24)
noScanLabel.textAlignment = NSTextAlignment.center
tableView.backgroundView = noScanLabel
tableView.separatorStyle = .none
return 0
}
}
这是结果。
看起来不错。但是,如何做到这样,我可以将另一行文本包含在向下箭头中,指向凸起的中心按钮。就像“点击这里开始扫描”?
我已经尝试在noScanLabel.text
字段中添加新的行字符,但这并没有解决。任何指向正确方向的指针都会有所帮助。
请您详细说明一下吗? – noblerare