iOS开发:UITableView自定义SectionHeader

来源:互联网 发布:淘宝如何找相似 编辑:程序博客网 时间:2024/05/22 00:33

要自定义TableView的sectionHeader view(sectionFooter同理),需要实现UITableViewDelegate如下的两个方法:

//自定义section的头部
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{

 UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 375, 40)];//

  //add your code behind

  

 return view;

}

//自定义section头部的高度

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

{

    return120.0;

}

注意,UITableView的style:为grouped时,section header会和cell一样划出界面;为plain的时,section header在当前section的cell没有全部滑出界面时,section一直会停留在tableView的顶部。
0 0
原创粉丝点击