iOS开发之UITableView自定义Header视图和自定义Footer视图

来源:互联网 发布:淘宝贝南海幼儿园应聘 编辑:程序博客网 时间:2024/05/23 01:16

//自定义Header视图

- (nullable UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{

    if (section == 0) {

        UIView *view = [[UIViewalloc]init];

      

        UIImageView *imageViews = [[UIImageViewalloc]initWithFrame:CGRectMake(20,30, 20, 25)];

        imageViews.image = [UIImageimageNamed:@"help_basic"];

        [view addSubview:imageViews];

        

        UILabel *label1=[[UILabelalloc]initWithFrame:CGRectMake(50,30, KYRect.size.width-20,25)];

        //label1.layer.borderWidth = 1;

       // label1.layer.borderColor = [[UIColor blackColor]CGColor];

        label1.textAlignment =NSTextAlignmentLeft;

        label1.text=@"基本信息";

        label1.font = [UIFontboldSystemFontOfSize:23.0f];

        

        UIView *line = [[UIViewalloc]initWithFrame:CGRectMake(0,69, KYRect.size.width,1)];

        line.backgroundColor = [UIColorlightGrayColor];

        line.alpha = 0.3f;

        [view addSubview:line];

        [view addSubview:label1];

        return view;

    }

    if (section == 1) {

        UIView *view = [[UIViewalloc]init];

        

        UIImageView *imageViews = [[UIImageViewalloc]initWithFrame:CGRectMake(20,30, 22, 25)];

        imageViews.image = [UIImageimageNamed:@"help_question"];

        [view addSubview:imageViews];

        

        UILabel *label1=[[UILabelalloc]initWithFrame:CGRectMake(50,30, KYRect.size.width-20,25)];

        //label1.layer.borderWidth = 1;

        // label1.layer.borderColor = [[UIColor blackColor]CGColor];

        label1.textAlignment =NSTextAlignmentLeft;

        label1.text=@"使用问题";

        label1.font = [UIFontboldSystemFontOfSize:23.0f];

        

        UIView *line = [[UIViewalloc]initWithFrame:CGRectMake(0,69, KYRect.size.width,1)];

        line.alpha = 0.3f;

        line.backgroundColor = [UIColorlightGrayColor];

        [view addSubview:line];

        [view addSubview:label1];

        return view;

    }

    return 0;

}

//自定义Footer视图

- (nullable UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{

    return 0;

}