3

Is it possible to give the section header in ui tableview an offset to stop programmatically?

So, that the section header stop 100 px from top?

Eric Aya
  • 69,473
  • 35
  • 181
  • 253
Auryn
  • 1,117
  • 1
  • 13
  • 37
  • check this https://stackoverflow.com/questions/23969587/is-it-possible-to-have-a-fixed-uitableview-header-while-using-sections – Raksha Saini Jul 26 '17 at 10:19

3 Answers3

4

I think this should work:

override func scrollViewDidScroll(_ scrollView: UIScrollView)
{
    super.scrollViewDidScroll(scrollView)
    let inset: CGFloat = 73
    if scrollView.contentOffset.y < inset && scrollView.contentOffset.y > 0 {
        scrollView.contentInset = UIEdgeInsets(top: scrollView.contentOffset.y, left: 0, bottom: 0, right: 0)
    } else {
        if scrollView.contentOffset.y < 0 {
            scrollView.contentInset = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
        } else {
            scrollView.contentInset = UIEdgeInsets(top: inset, left: 0, bottom: 0, right: 0)
        }
    }
}
ANE
  • 243
  • 1
  • 10
1

You can try this one

CGFloat newViewHeight = 40;

UIView *newView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.tableView.bounds.size.width, newViewHeight)];

self.tableView.tableHeaderView = newView;
self.tableView.contentInset = UIEdgeInsetsMake(-newViewHeight, 0, 0, 0);

Section headers will now scroll just like any regular cell.

Philipp Otto
  • 4,061
  • 2
  • 32
  • 49
Megha_Singh
  • 100
  • 4
0

You can use property of UIScrollView: contentInset. And style for a table view UITableViewStyleGrouped (.group in Swift). This is my example of such UI: enter image description here

If you want to avoid header moving, set Bounce Vertical property to NO.

Andrew Romanov
  • 4,774
  • 3
  • 25
  • 40
  • Thanks for the Comment, The UIEdgeInsets make the right thing with the header, but the content get also the offset, but I only want to stop the header earlier because the tableview is behind a transparent view – Auryn Jul 26 '17 at 12:02