iOS 8 UITableView separator inset 0 not working

前端 未结 30 1396
清酒与你
清酒与你 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条回答
  •  有刺的猬
    2020-11-22 15:16

    After having seen the answers at floor 3, I tried to figure out what the relationship of setting up the separator between TableView & TableViewCell and did some test. Here are my conclusions:

    1. we can consider that setting the cell's separator to zero has to move the separator in two steps: first step is to set cell's separatorinset to zero. second step is to set cell's marginlayout to zero.

    2. set the TableView's separatorinset and marginlayout can affect the Cell's separatorinset. However, from the test, I find that the TableView's separatorinset seem to be useless, TableView's marginlayout can actually affect cell's marginlayout.

    3. set Cell's PreservesSuperviewLayoutMargins = false, can cut off TableView's marginlayout effect on Cells.

    4. one of the solutions:

      func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
          var cell = UITableViewCell()
      
          cell.preservesSuperviewLayoutMargins = false
          cell.separatorInset = UIEdgeInsetsZero
          cell.layoutMargins = UIEdgeInsetsZero
      
          return cell
      }
      

提交回复
热议问题