Reputation: 25058
I have a UITableView with headings on top of a textured background. I want the header to stick at the top, which they do, but I don't want the cells to show behind it as they go by. Here is an example:
New Content is the header. You can see the rows of data under it as they scroll by. I can't set the background of the header because it has to show the texture from the window behind it. How can I not show the rows underneath the header?
Upvotes: 5
Views: 5149
Reputation: 15
It's works for me.
func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
// bring first cell to front
if indexPath.row == 0 {
tableView.bringSubviewToFront(cell)
}
}
Upvotes: 1
Reputation: 10407
You can make the background image for the header the same texture as the UITableCell. You can also make the lower border have a drop shadow. The cells will appear to slip underneath the table headings.
Implement
(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
and return a view with an UIImageView
background. You will have to futz with this image a bit in photoshop to get the effect you're looking for.
Upvotes: 0
Reputation: 536028
Basically, you can't - not without making the headers opaque. The cells are what is behind the headers, so if you make the headers transparent, the cells are what you will see behind them.
Upvotes: 2