0

I have a UITableView. I figured out how to change the background color for the section headers. However, it also changes the bottom area that contains "no section/rows" to the same color. I don't want this.

Is there anyway I can set the color of that area to be a different color than the section headers?

See example picture for more information.Area in blue at the bottom is the part that I want to be a different color

Any help is greatly appreciated. I've done research but I haven't found anything yet.

Sandy D.
  • 3,166
  • 1
  • 20
  • 31
  • Hm... That's strange. Could you post your code from `numberOfSectionsInTableView:` and `numberOfRowsInSection:` and your header methods? – Lyndsey Scott Dec 12 '14 at 03:40
  • I actually did this one in Interface Builder. The only thing that I did via code for this `willDisplayHeaderView' method and it was used only to set the text color of the section headers. – Sandy D. Dec 12 '14 at 03:43
  • did you set background color for table view? – Clement Prem Dec 12 '14 at 03:44
  • In IB to set the section color background, I changed the background color for the View. It seems like that is what affects all 3 areas. Is there a way to set only the section header colors programmatically? – Sandy D. Dec 12 '14 at 03:45
  • may be you can return a custom view with blue color using tableView:viewForHeaderInSection: method – Clement Prem Dec 12 '14 at 03:47
  • @Clement in `viewForHeaderInSection` method, I did this: `UIView *view = self.tableView.tableFooterView; view.backgroundColor = [UIColor blueColor]; return view;` Now I'm getting this error: Setting the background color on UITableViewHeaderFooterView has been deprecated. Please use contentView.backgroundColor instead. My application also crashes after doing this. So, I'm not sure what is going on. – Sandy D. Dec 12 '14 at 04:00
  • @Clement I figured out how to add just a color to the section headers. In `willDisplayHeaderView` method, I was able to get the contentView and was able to set the background color by doing this: `UITableViewHeaderFooterView *header = (UITableViewHeaderFooterView *)view;header.contentView.backgroundColor = [UIColor blueColor];` However, for some reason the second header has a white line above it -- like there is some kind of padding added. – Sandy D. Dec 12 '14 at 04:09

1 Answers1

0

Basically, what I had to do was:

In Interface Builder, change the color of the view to what you want displayed at the bottom.

I used the same color that I had set for my table cell rows.

For the section headers:

In the willDisplayHeaderView method, do:

UITableViewHeaderFooterView *header = (UITableViewHeaderFooterView *)view;
header.contentView.backgroundColor = [UIColor blueColor];    

Please note: If you get a white/gray line above the section header - this deals with the footer. So, in viewDidLoad method, set the table footer height to 0:

self.tableView.sectionFooterHeight = 0.0;
Sandy D.
  • 3,166
  • 1
  • 20
  • 31