iOS 8 UITableView separator inset 0 not working

前端 未结 30 1776
清酒与你
清酒与你 2020-11-22 14:38

I have an app where the UITableView\'s separator inset is set to custom values - Right 0, Left 0. This works perfectly in iOS 7.

30条回答
  •  旧时难觅i
    2020-11-22 15:14

    After much investigation...

    Here's the only way to fully control this stuff (that I could find)

    To fully control both separator insets and layout margins on each cell. Do this in the willDisplayCell method on your UITableviewDelegate.

    func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) {
        cell.layoutMargins = UIEdgeInsetsZero
        cell.contentView.layoutMargins = UIEdgeInsetsMake(0, 10, 0, 10)
        cell.separatorInset = UIEdgeInsetsMake(0, 0, 0, 0)
    }
    

    The cell object controls the separator, and the contentView controls everything else. If your separator inset spaces are showing up in an unexpected color this should solve it:

    cell.backgroundColor = cell.contentView.backgroundColor
    

提交回复
热议问题