【发布时间】:2018-07-05 23:08:33
【问题描述】:
我有页脚功能。 我想在这个单元格的顶部显示分隔符并将其隐藏在底部。
override func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
let footer = UITableViewCell(frame: CGRect(x: 0, y: 0, width: tableView.frame.width, height: 50))
let label = UILabel(frame: CGRect(x: 0, y: 0, width: tableView.frame.width, height: 50))
label.text = "HELLO"
label.textAlignment = .center
label.textColor = UIColor.lightGray
footer.addSubview(label)
tableView.tableFooterView = footer
return footer
}
如何以编程方式打开分隔符?
【问题讨论】:
-
添加一个高度设置为 1 且
backgroundColor设置为您想要的分隔符颜色的 UIView 怎么样? -
@dr_barto 有趣的想法
-
@dr_barto 但是当我在代码中更改高度时,它仍然具有静态页脚高度
-
我的意思是,您应该创建一个新的 UIView,将其高度设置为 1,并将其作为子视图添加到您的页脚视图中。
-
@dr_barto 我这样做了。它仍然有页脚的高度
标签: ios swift uitableview footer separator