How to make the section header of a UITableView completely transparent

2k views Asked by At

I have a UIViewController with a UIImage as the entire background image. I put a UITableView into my view controller and constraint it to the bottom, leading, trailing and half the height.

The goal is to make the Section Header of the table view be completely transparent so that the background image is visible through the section header.

Doing this just makes it gray and not clear/transparent:

self.tableView.backgroundColor = [UIColor clearColor];
self.tableView.opaque = NO;

How can I make it transparent?

1

There are 1 answers

0
0yeoj On BEST ANSWER

If you declared your tableHeader view using self.tableView.tableHeaderView = YourHeaderView;

Update it by

UIView *tempTableView = self.tableView.tableHeaderView;

then modify it by: tempTableView.backgroundColor = [UIColor clearColor];

of directly like: self.tableView.tableHeaderView.backgroundColor = [UIColor clearColor];

but if you are using UITableView Delegate:

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

your need to update it by:

UIView *tempTableView = [self.tableView viewForHeaderInSection:YourSection];

then modify: tempTableView.backgroundColor = [UIColor clearColor];