我想让我的 UITableView 的最后一个单元格分隔符占据全长
我试过这段代码,但它没有改变任何东西:
// in UITableViewDelegate
func tableView(tableView: UITableView, willDisplayCell cell:UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) {
cell.separatorInset = UIEdgeInsetsZero
cell.layoutMargins = UIEdgeInsetsZero
cell.preservesSuperviewLayoutMargins = false
}
//UITableViewDataSource
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
tableView.separatorStyle = UITableViewCellSeparatorStyle.SingleLine
tableView.separatorInset = UIEdgeInsetsZero
}
最佳答案
这都是关于 preservesSuperviewLayoutMargins
属性的。假设您的 TableView 有 1 个部分和 20 行。然后你会说:
if indexPath.row == 19 {
cell.separatorInset = UIEdgeInsetsZero
cell.layoutMargins = UIEdgeInsetsZero
cell.preservesSuperviewLayoutMargins = false
} else {
cell.preservesSuperviewLayoutMargins = true
}
你可以看到它有效:
关于ios - 如何让 UITableView 的最后一个单元格分隔符占据全长?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30671824/