美文网首页
tableView两种style的区别,如何在UITableVi

tableView两种style的区别,如何在UITableVi

作者: iOS刘耀宗 | 来源:发表于2017-05-10 14:46 被阅读190次

    tableView有两种style:UITableViewStylePlain,          // 常规普通的展现方式

    1.有多段时 段头停留(自带效果)

    2.没有中间的间距和头部间距(要想有的重写UITableViewCell \UITableViewHeaderFooterView里面的setFrame方法)

    扩展:让段头不停留(取消粘性效果)

    - (void)scrollViewDidScroll:(UIScrollView*)scrollView{    if (scrollView== self.tableView)    {        CGFloat sectionHeaderHeight =20;//这个高度就是你的header的高度

    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);}    }}

    UITableViewStyleGrouped        // 适用于分组

    没有悬浮的效果,头部和每个secontion 中间会有间距,可自己进行设置.如果想要去掉头部和中间间隔

    在使用的时候回发现,在代理方法里面-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section

    {

    return 0.01;

    }

    头部仍然会有一段间距,这个间距实际上是tableView.tableHeaderView的高度带来的,解决方法如下:

    1.设置标头的高度为特小值 (不能为零 为零的话苹果会取默认值就无法消除头部间距了)

    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 0.001)];

    view.backgroundColor = [UIColorredColor];

    self.tableView.tableHeaderView = view;

    2.写代理方法(中间的留白其实是段尾的高度 代理的作用设置段尾的高度 返回值也不能为0)

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

    {

    return 0.01f;

    }

    特殊的处理方法也能实现该效果

    1.    self.tableView.contentInset = UIEdgeInsetsMake(-44, 0, 0, 0);

    2.重写UITableViewHeaderFooterView的

    -(void)setFrame:(CGRect)frame{

    frame.size.height+=10;

    [super setFrame:frame];

    }

    承接APP,小程序,公众号开发. 性价比高.+V信:17723566468  有单子也可找我一起做哦

    相关文章

      网友评论

          本文标题:tableView两种style的区别,如何在UITableVi

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