zoukankan      html  css  js  c++  java
  • iOS tableView 中 UITableView中UITableViewStyleGrouped和UITableViewStylePlain的区别

    一,

    UITableViewStyleGrouped

    注意:去掉头部和中间间隔
    正确的理解方法
    1.设置标头的高度为特小值 (不能为零 为零的话苹果会取默认值就无法消除头部间距了)
    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 0.001)];
    view.backgroundColor = [UIColor redColor];
    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];
    }


    例如:

    _themeTable= [[UITableView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height - 70) style:UITableViewStyleGrouped];

    UITableViewStyleGrouped效果如下图

     二,

    UITableViewStylePlain

    1.有多段时 段头停留(自带效果)
    2.没有中间的间距和头部间距(要想有的重写UITableViewCell UITableViewHeaderFooterView里面的setFrame方法)
    扩展:让段头不停留(取消粘性效果)
    - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    CGFloat sectionHeaderHeight = 30;
    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);
    }
    }


    例如:

    _themeTable= [[UITableView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height - 70) style:UITableViewStylePlain];

    UITableViewStylePlain效果如图

    -cell之间无隔

  • 相关阅读:
    运行.bat批处理,CMD窗口隐藏,并制作为EXE文件
    TinyXML:一个优秀的C++ XML解析器(转载)
    2013编程之美资格赛【传话游戏】
    linux GTK教程(消息机制/标签/按钮/图像/文本/对话框/菜单/容器)
    c++强制类型转换(总结)
    string与char*的转换(转载)
    网络数据包捕获函数库Libpcap安装与使用(非常强大)
    Linux 高级Socket编程
    linux GTK 安装
    .dll和.lib文件的生成和使用 c++
  • 原文地址:https://www.cnblogs.com/Lovexiaohuzi/p/5643117.html
Copyright © 2011-2022 走看看