Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITableViewStylePlain with Opaque Header

Tags:

uitableview

I implemented a UITableView with style UITableViewStylePlain. I am using a custom header view with a solid background color, which should be opaque. But the headers are not opaque, leaving the cells visible as they scroll under the header. I want to make the headers opaque, but I don't see how this would done.

like image 950
Jim Avatar asked Jan 17 '23 20:01

Jim


1 Answers

When table view is plain, it's visible if at least one of cells in its section is on the screen. So looks like table view sets a background view for header somewhere internally with some alpha. But you could set background view to a custom view and to set background to it then.

You could do this when you create a custom header view in tableView:viewForHeaderInSection::

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
  UITableViewHeaderFooterView *header = ...
  header.backgroundView = [UIView new];
  header.backgroundView.backgroundColor = [UIColor greenColor];

  return header;
}

Or if you don't want to create a custom header view, then probably you could set the background in tableView:willDisplayHeaderView:forSection: fir the default header views.

like image 190
yas375 Avatar answered Feb 20 '23 15:02

yas375