gskbyte / GSKStretchyHeaderView

A generic stretchy header for UITableView and UICollectionView
MIT License
1.75k stars 185 forks source link

Static table headers have gap with top of table #48

Closed hrsalehi closed 7 years ago

hrsalehi commented 7 years ago

When I add GSKStretchyHeaderView to a static table view, headers not stick to the top and they have gap with size of the maximum stretchy header to the top.


    headerView = Bundle.main.loadNibNamed("HeaderView", owner: self, options: nil)![0] as? UIView

    let hView = GSKStretchyHeaderView(frame: CGRect(x: 0 ,y:0 ,width: self.view.frame.size.width ,height:self.view.frame.size.width * 2 / 3))
    hView.addSubview(headerView!)
    hView.minimumContentHeight = 64
    hView.maximumContentHeight = 250

    self.tableView.addSubview(hView)

and here is my sticky header

override func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
        if  section == 1 {
            self.viewHeaderPrice.backgroundColor = UIColor.red
            return self.viewHeaderPrice
        }
        return super.tableView(tableView, viewForHeaderInSection: section)
    }

    override func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        if  section == 1 {
            return self.viewHeaderPrice.height
        }
        return 0
    }

You can see the red header (Section 1) remains in the middle of screen with scroll

photo

hrsalehi commented 7 years ago

I figured the problem out. I didn't set this value hView.manageScrollViewInsets = false

gskbyte commented 7 years ago

Cool, glad it works for you!