我有一个 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/