[英]How to put separator line on UITableView to specific section?
我有一些部分的UITableView
。 我只希望一个部分的行有分隔线。
我尝试了这个:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
...
if indexPath.section == 1 {
cell.separatorInset = UIEdgeInsetsMake(0, 1, 0, 0) // With other values too.
}
...
return cell
}
但什么也没发生。
您可以创建UITableViewCell的扩展:
extension UITableViewCell {
func hideSeparator() {
self.separatorInset = UIEdgeInsets(top: 0, left: self.bounds.size.width, bottom: 0, right: 0)
}
func showSeparator() {
self.separatorInset = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
}
}
因此,您可以在tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath)
使用它
if indexPath.section == 1 {
cell.hideSeparator()
} else {
cell.showSeparator()
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.