我使用此代码为表格视图部分标题设置颜色等
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
// create the parent view that will hold header Label
UIView* customView = [[UIView alloc] initWithFrame:CGRectMake(10.0, 0.0, 300.0, 44.0)];
// create the button object
UILabel * headerLabel = [[UILabel alloc] initWithFrame:CGRectZero];
headerLabel.backgroundColor = [UIColor clearColor];
headerLabel.opaque = NO;
headerLabel.textColor = [UIColor whiteColor];
headerLabel.highlightedTextColor = [UIColor whiteColor];
headerLabel.font = [UIFont boldSystemFontOfSize:18];
headerLabel.shadowColor = [UIColor blackColor];
headerLabel.shadowOffset = CGSizeMake(0, 1.0);
headerLabel.frame = CGRectMake(10.0, 0.0, 300.0, 44.0);
if (section == 0) {
headerLabel.text = @"Section 0 header";
[customView addSubview:headerLabel];
}
if (section == 1) {
//headerLabel.text = @"Section 1 header";
//[customView addSubview:headerLabel];
customView = nil;
tableView.tableHeaderView = nil;
}
if (section == 2) {
headerLabel.text = @"Section 2 header";
[customView addSubview:headerLabel];
}
return customView;
}
在第 1 节中,我不想要标题,但第 0 节和第 1 节之间仍然有更大的空间。