ios - 如何在 UITableView 中设置分隔符的全宽

我有一个 UITableView,其中分隔符没有全宽。它在左侧前 10 个像素处结束。我在 viewDidLoad() 中玩弄这段代码。

self.tableView.layoutMargins = UIEdgeInsetsZero;

当您可以选择自定义或默认选择器时,也可以在 Storyboard 中。现在所有填充的单元格都没有全宽选择器,但空的单元格有全宽。

我该如何解决这个问题?

最佳答案

这适用于我在使用 Xcode 6.4 和 Swift 1.2 的 iOS 8.4 - 9.0 设备上:

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    var cell = UITableViewCell()


    cell.preservesSuperviewLayoutMargins = false
    cell.separatorInset = UIEdgeInsetsZero
    cell.layoutMargins = UIEdgeInsetsZero

    return cell
}

Swift 5 更新:

cell.preservesSuperviewLayoutMargins = false
cell.separatorInset = UIEdgeInsets.zero
cell.layoutMargins = UIEdgeInsets.zero

https://stackoverflow.com/questions/26519248/

相关文章:

ios - 如何使 UIButton 文本对齐中心?使用 IB

iphone - 什么是使 iOS 应用程序崩溃的可靠方法?

ios - Objective-C 和 Swift URL 编码

objective-c - 为什么在 C 中将 1,000,000,000 写为 1000*1000

objective-c - 关于iOS5 SDK中自动引用计数的一些问题

ios - 以编程方式在 UIStackView 中添加 View

iphone - 错误 : The service is invalid

ios - 无法同时满足约束,将尝试通过打破约束来恢复

ios - 如何在 UILabel 中嵌入小图标

ios - 使用 glob 获取目录中的文件列表