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

方法如下:

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

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


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

headerLabel.backgroundColor = [UIColor clearColor];

headerLabel.opaque = NO;

headerLabel.textColor = [UIColor lightGrayColor];

headerLabel.highlightedTextColor = [UIColor whiteColor];

headerLabel.font = [UIFont boldSystemFontOfSize: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;

}

你可能感兴趣的:(ios,测试,UIView)