美文网首页iOS归纳
iOS开发- tableView取消头部(section hea

iOS开发- tableView取消头部(section hea

作者: 彗星来的那一夜 | 来源:发表于2018-07-27 19:14 被阅读1890次

以下分别是三种方法:
1.可以将tableview的style 由plain改成grouped , iOS11之后 修改sectionHeader的高度需要重写 tableView 的 heightForHeader viewForHeader 方法 ,同理sectionFooter 同样需要重写这两个方法

2.重写一下scrollView的代理方法

-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
    if(scrollView == self.tableView) {
    CGFloat sectionHeaderHeight = 40;
    if (scrollView.contentOffset.y<=sectionHeaderHeight&&scrollView.contentOffset.y>=0) {
        scrollView.contentInset = UIEdgeInsetsMake(-scrollView.contentOffset.y, 0, 0, 0);
    } else if (scrollView.contentOffset.y>=sectionHeaderHeight) {
        scrollView.contentInset = UIEdgeInsetsMake(-sectionHeaderHeight, 0, 0, 0);
     }
    }
}

3.sectionHeader 可以做成一个cell(改变一下背景颜色) 这样看起来和section header没什么区别

相关文章

网友评论

    本文标题:iOS开发- tableView取消头部(section hea

    本文链接:https://www.haomeiwen.com/subject/eoggmftx.html