UITableView实战总结(三)——HeaderInSection、FooterInSection和tableHeaderView、tableFooterView

一、HeaderInSection、FooterInSection

1、HeaderInSection(对Section的Header的内容和高度的设置)

  • 不显示Header(隐藏顶部分隔线)
 - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
 { 
     return 0.001;
 }
  • 需要设置和显示Header的内容与高度
 // 设置Header内容
 - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
 {
     UIView *view = [[UIView alloc] init];
     view.backgroundColor = [UIColor whiteColor];
     return view;
 }

 // 返回Header高度
 - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
 {
     return 10;
 }

2、FooterInSection(对Section的Footer的内容和高度的设置)

  • 不显示Footer(隐藏底部分隔线)
 - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
 {
     return 0.001;
 }
  • 需要设置和显示Footer的内容与高度
 - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
 {
     UIView *view = [[UIView alloc] init];
     view.backgroundColor = [UIColor whiteColor];
     return view;
 }

 - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
 {
     return 60;
 }

二、tableHeaderView、tableFooterView

1、tableHeaderView

  • headerView的申明
@property (nonatomic,strong) UIView *headerView;
  • 在tableView初始化时调用
_tableView.tableHeaderView = self.headerView;
  • 创建方法
 - (void)createTableHeaderView
 {
     CGRect frame = CGRectMake(0, 0, ScreenWidth, 10);
     self.headerView = [[UIView alloc] initWithFrame:frame];
     self.headerView.backgroundColor = [UIColor whiteColor];
 }

2、tableFooterView

  • footerView的申明
@property (nonatomic,strong) UIView *footerView;
  • 在tableView初始化时调用
_tableView.tableFooterView = self.footerView;
  • 创建方法
 - (void)createTableFooterView
 {
     CGRect frame = CGRectMake(0, 0, ScreenWidth, 60);
     self.footerView = [[UIView alloc] initWithFrame:frame];
     self.footerView.backgroundColor = [UIColor whiteColor];
     [self.footerView addSubview:self.button];
 }
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 版权声明:未经本人允许,禁止转载. 1. TableView初始化 1.UITableView有两种风格:UITa...
    萧雪痕阅读 2,918评论 2 10
  • 概述在iOS开发中UITableView可以说是使用最广泛的控件,我们平时使用的软件中到处都可以看到它的影子,类似...
    liudhkk阅读 9,086评论 3 38
  • UITableView 是 iOS 开发中必不可少的一个控件,基本上每一个项目都会有多个地方会用到。详细的了解UI...
    破夕_____________阅读 2,113评论 0 4
  • UITableView有两种样式: UITableView的结构:UITableView由头部,尾部,和中间一连串...
    degulade阅读 844评论 1 3
  • 三年级的第一个感受,早上去学校,我去吃粉,小姑娘可以自己走路进学校,也会主动跟值日老师打招呼。 开学典礼上,蜗牛与...
    木木王_deb5阅读 278评论 0 0