How to change a grouped UITableView cell's background to black (or non-white)?

11,969

Solution 1

I believe that the rounded corners of the Grouped style are actually backgrounds of the table cells. Thus you can't just replace the white part, because it's not solid color with drawn border - it's ImageView acting as backgroundView for the cell (using different graphics depending of the cell row and number of rows in section).

So either you try with your own graphics so you can keep the roundness (I'm trying something out for myself, not fully figured yet) or set each cell.backgroundView to nil and use cell.backgroundColor = [UIColor blackColor];

Solution 2

If you edit the cell.backgroundColor instead of the cell.contentView.backgroundColor it should work for you.

Share:
11,969
Meltemi
Author by

Meltemi

Updated on June 04, 2022

Comments

  • Meltemi
    Meltemi almost 2 years

    Just want to make sure I'm not overlooking something obvious... It seems like it should be trivial to set the background color (black is fine) of a UITableView's cell to something other than white or completely transparent so that you can display your data with white text. However, with my attempts I lose the corners on my grouped table view and it all looks like crap.

    I've seen & understand the methods described by Matt Gallagher about customizing TableView cells with exotic gradients, etc. but wanted to be certain before heading down that path...

    • Vaerenberg
      Vaerenberg almost 15 years
      You want to change the background of your tableview or tableview cell? To change the bkg of the table, set the background of your view to black or whatever color you want. And in your viewcontroller, do this self.tableView.backgroundColor = [UIColor clearColor];
    • Meltemi
      Meltemi almost 15 years
      I'm interested in changing the tableview cell's background. Thought I was clear in the description but I edited the title anyway.
  • FalconNL
    FalconNL over 12 years
    +1 for set cell.backgroundView to nil and use cell.backgroundColor = [UIColor blackColor];