0

I have a plain UITableView in my project with sectioned data. For each section I have a header for every letter so it looks like the contacts app on the iPhone. The only thing I want to change, however, is the color of the header background. This code doesn't work but this is what I want to achive:

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView *headerView = [[[UITableView alloc] init] tableHeaderView];
    [headerView setBackgroundcolor:[UIColor redColor]];
    return headerView;
}

I could design my headerView from scratch by initing a UIView and building it to look like the header does now, but then I need to write much more code and have to guess the properties since I don't know what the code for a regular header is and since I just want to change the background color I thought there might be an easier way.

Thanks!

4

1 回答 1

0

I just wanted to add an answer to this question myself if anyone else come across this issue and want to know what to do. The short answer is that you can't simple just change the color of the header, but, you can write some more code to mimic the gradient and shadows to make it look like the headerView. The exact code for doing this can be found in this other question: How can I access the standard viewForHeaderInSection for a tableView?

于 2013-12-22T10:55:04.993 回答