tableView的表头

来源:互联网 发布:日本强大知乎 编辑:程序博客网 时间:2024/06/05 20:15
表头和页眉是有区别的,表头是整个tableview的头部,而页眉相当于区头,是tableview每个分区的头部。并且创建页眉的时候tableview的style应该是Group,而创建表头的时候则Pline和group都可以。表尾和区尾亦如是。

1.创建headerview(注意创建表头的代码一定要在布局tableview的代码之前调用)

-(void)setHeadView{

    headView =[[UIView alloc]initWithFrame:CGRectMake(0, 0, WIDTH, SP_W(80))];

/*

在headerview上添加相应的控件

*/

}

-(void)setFooterView {

    footerView = [[UIView allocinit];

    footerView.frame = CGRectMake(00WIDTH115);

    footerView.backgroundColor = [UIColor whiteColor];

    //背景阴影

    UILabel *cutLabel = [[UILabel allocinitWithFrame:CGRectMake(00WIDTH10)];

    cutLabel.backgroundColor = BGCOLOR;

    [footerView addSubview:cutLabel];

    

    //年票抵扣

    UILabel *yearLable = [[UILabel allocinit];

    yearLable.text = @"年票抵扣";

    CGSize yearSize = [yearLable sizeThatFits:CGSizeMake(WIDTH25)];

    yearLable.frame = CGRectMake(10,  CGRectGetMaxY(cutLabel.frame) + 15, yearSize.width25);

    yearLable.textColor = TEXTCOLOR;

    yearLable.font = FONT(15);

    [footerView addSubview:yearLable];

}
2.在布局tableview的时候写如下代码:

orderTab.tableHeaderView = headView; //表头

orderTab.tableFooterView = footerView; //表尾


0 0