ios:改变tableview的titleForHeaderInSection字体颜色设置

来源:互联网 发布:linux安装eclipse 编辑:程序博客网 时间:2024/06/05 04:59

方法如下:

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

UIView* customView = [[[UIViewalloc] initWithFrame:CGRectMake(10.0, 0.0, 300.0, 44.0)]autorelease];


UILabel * headerLabel = [[[UILabelalloc] initWithFrame:CGRectZero]autorelease];

headerLabel.backgroundColor = [UIColorclearColor];

headerLabel.opaque = NO;

headerLabel.textColor = [UIColorlightGrayColor];

headerLabel.highlightedTextColor = [UIColorwhiteColor];

headerLabel.font = [UIFontboldSystemFontOfSize:18];

headerLabel.frame = CGRectMake(10.0, 0.0, 300.0, 44.0);

    

        if (section == 0) {

            headerLabel.text =  @"测试1";

        }else if (section == 1){

            headerLabel.text = @"测试2";

        }else if (section == 2){

            headerLabel.text = @"测试3";

        }else if (section == 3){

            headerLabel.text = @"测试4";

        }

     

[customView addSubview:headerLabel];

    

return customView;    

}

//别忘了设置高度

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

{

        return 44.0;

}

原创粉丝点击