删除iOS中的UITableView节背景色



我有一个包含7个部分的UITableView,我想将UITableView部分的现有"浅灰色"颜色(默认颜色)删除为"透明颜色"。

我试过这个代码,但它不起作用,请帮帮我。

代码

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView *tempView=[[UIView alloc]initWithFrame:CGRectMake(0,200,300,244)];
    tempView.backgroundColor=[UIColor clearColor];
    UILabel *tempLabel=[[UILabel alloc]initWithFrame:CGRectMake(15,0,300,44)];
    tempLabel.backgroundColor=[UIColor clearColor];
    tempLabel.shadowColor = [UIColor blackColor];
    tempLabel.shadowOffset = CGSizeMake(0,2);
    tempLabel.textColor = [UIColor redColor]; //here you can change the text color of header.
    tempLabel.font = [UIFont fontWithName:@"Helvetica" size:14];
    tempLabel.font = [UIFont boldSystemFontOfSize:14];
    NSString *sectionName;
    switch (section)
    {
        case 0:
            sectionName = NSLocalizedString(@"Mobile Number", @"Mobile Number");
            break;
        case 1:
            sectionName = NSLocalizedString(@"Name", @"Name");
            break;
        case 2:
            sectionName = NSLocalizedString(@"Email", @"Email");
            break;
        case 3:
            sectionName = NSLocalizedString(@"Gender", @"Gender");
            break;
        case 4:
            sectionName = NSLocalizedString(@"Age", @"Age");
            break;
        case 5:
            sectionName = NSLocalizedString(@"Notes", @"Notes");
            break;
        case 6:
            sectionName = NSLocalizedString(@" Type", @" Type");
            break;
        default:
            break;
    }
    tempLabel.text=sectionName;
    [tempView addSubview:tempLabel];
    return tempView;
}

使用tableView:viewForHeaderInSection:还需要实现:

  • CCD_ 2。这应该为标头返回一个适当的non-zero height
  • 还要确保您没有同时实现tableView:titleForHeaderInSection:

您应该只使用其中一个(viewForHeadertitleForHeader)。

最新更新