1

I'm developing a section of my app with a UITableView. I added it programmatically with this set of constraints. I'm not considering bottom safe area because I want content over it.

NSLayoutConstraint.activate([
    tableView.topAnchor.constraint(equalTo: customHeader.bottomAnchor),
    tableView.leadingAnchor.constraint(equalTo: self.view.leadingAnchor),
    tableView.trailingAnchor.constraint(equalTo: self.view.trailingAnchor),
    tableView.bottomAnchor.constraint(equalTo: self.view.bottomAnchor)
])

So, I noticed this weird behavior of scroll indicator:

enter image description here

green is customHeader, blue is the tableView background color and orange is the first cell. When I pull down the tableview and I reach the first cell, the scroll indicator is not at ZERO position, but only graphically. In fact tableView.scrollIndicatorInsets.top is zero.

So I tried to set it to -20, for example, and the scroll indicator has its zero behind the customHeader, as expected. So it starts to appear outside the tableView.

I tried to set tableView.scrollIndicatorInsets.top = .leastNonZeroMagnitude and it works. Now the indicator starts at Zero.

I studied this behavior and I found that if I change the bottom constraint from:

tableView.bottomAnchor.constraint(equalTo: self.view.bottomAnchor)

to:

tableView.bottomAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.bottomAnchor)

everything works fine, without the need to set manually the scroll indicator position. But in this way I lose the possibility to have table view content over safe area. I thought it could be a problem of automaticallyAdjustScrollViewInsets for the vc I'm working on, but it's not the case.

Any advice on this? I think it's a bug. I'm working with Xcode 11.4 and Swift 5.2.

Thanks.

Edoardo Vicoli
  • 227
  • 2
  • 8
  • see this: https://stackoverflow.com/questions/18880341/why-is-there-extra-padding-at-the-top-of-my-uitableview-with-style-uitableviewst – Hasti Ranjkesh Apr 17 '20 at 16:46
  • already consulted that: all the posted solutions don't work – Edoardo Vicoli Apr 17 '20 at 16:53
  • Add these code in your view controller's viewDidLoad() method: tableView.layoutMargins = UIEdgeInsets.zero , tableView.separatorInset = UIEdgeInsets.zero. Then look for you cellForRowAt method and add this: cell.layoutMargins = UIEdgeInsets.zero – Hasti Ranjkesh Apr 17 '20 at 17:09
  • separator? I'm asking for scrollIndicator, not separator – Edoardo Vicoli Apr 17 '20 at 17:12

0 Answers0