3

My UITableView spans the the size of the iPhone view, with a tableHeaderView holding additional content. Wanting the header to be clear and the rest of the table white, I set the background colour of the table to clear, and inside the view delegate method -(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath I set the cell's background to white.

This takes care of the cells with content, but there's now another problem: data for my table doesn't extend to the bottom, so there are a number of cell spaces that are clear.

I'm just looking for a clear tableHeaderView and white cells. Am I approaching this wrong? Setting the table background to white and the headerView to clear doesn't solve it.

MechEngineer
  • 1,399
  • 3
  • 16
  • 27

2 Answers2

0

Here is a work around which seems to at least work well enough:

  • Set the background colour of the UITableView to clear.
  • Set the background colour of cells to white in delegate method - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
  • Return a UIView with clear background as the header view.
  • Return a UIView with white background as the footer view and dynamically adjust its height with respect to the number of cells you have. That is, tableView.frame.size.height - (rowHeight * numberOfRows + headerHeight)
mkubilayk
  • 2,477
  • 3
  • 20
  • 27
0

I have another idea that I tried today and works. I made my tableView's background colour as [UIColor clearColor] and I put a scroll view behind the header view. My solution is to make sure that the scroll view that I have behind my table header view has clipsToBounds set as YES.

Enrico Susatyo
  • 19,372
  • 18
  • 95
  • 156