auryn31 auryn31 - 3 years ago 92
iOS Question

UITableView Section Header Stop Position

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?

ANE ANE
Answer Source

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)
        }
    }
}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download