美文网首页
iOS UITableView 设置了style 为UITabl

iOS UITableView 设置了style 为UITabl

作者: 香烟不灭 | 来源:发表于2020-07-02 10:14 被阅读0次

    UITableView 设置成UITableViewStylePlain 之后,如果设置section的 headview或者footview  会有悬浮效果。

    如果不想要悬浮效果,需要设置成UITableViewStyleGrouped 。

    虽然这样设置不会悬浮,但是我们没设置headview或者footview 也会自动显示一个默认高度的view。  

    如果只想显示自定义的headerview 不想显示footview ,就需要重写设置headerview和footview 的两个代理方法 

    -(UIView*)tableView:(UITableView*)tableViewviewForFooterInSection:(NSInteger)section{

    自定义view

        return nil;

    }

    -(UIView*)tableView:(UITableView*)tableViewviewForHeaderInSection:(NSInteger)section{

    自定义view

        return nil;

    }

    -(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{

        return0;

    }

    - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{

        return10;

    }

    以上代码,我只是设置了footview的高度,用来作为每个cell中间的间隔线。你可以按照自己的需求 自定义。

    相关文章

      网友评论

          本文标题:iOS UITableView 设置了style 为UITabl

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