ios - 如何让 UITableView 的最后一个单元格分隔符占据全长?

标签 ios uitableview

我想让我的 UITableView 的最后一个单元格分隔符占据全长

enter image description here

我试过这段代码,但它没有改变任何东西:

// 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
}

你可以看到它有效:

enter image description here

关于ios - 如何让 UITableView 的最后一个单元格分隔符占据全长?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30671824/

相关文章:

ios - spritekit : unable to detect collision

android - 如何确保 UUID 对于我的 BLE 服务或特性是唯一的?

ios - 在后台线程上将核心数据图像加载到 UITableViewCell 时崩溃

ios - 如何在邮件应用程序 iOS9 Swift/obj-C 中为单元格创建可扩展(可拉伸(stretch))操作

ios - UITableView 自定义单元格按钮从主视图中选择其他按钮?

ios - 无法从像 XMLParser 这样的异步函数调用 Segue

ios - 如何在不造成任何失真的情况下调整 UIImage 的大小和形状?

ios - UITableView 中 UILabel 的大小类别被随机忽略

iphone - 在 UITableViewCell 中启用/禁用编辑模式

ios - 停止调用 cellForRowAtIndexPath