4

I have a UITableViewController that I'm trying to custom style. I've got 95% of the way there, but am having trouble removing an odd shading from the cell background. I've highlighted what I'm trying to remove in this screen shot:

Normal View

To try and resolve this issue, I've dumped all the views that are composing my UITableView and then colored them to try and find the view I need to change:

Styled View

As you can see, I've been unable to color that specific spot. Said differently, I can't find a view associated with that spot.

How do I remove that shading from my cells?

Gavin Miller
  • 43,168
  • 21
  • 122
  • 188
  • You're putting _something_ custom in there, since it's a dark red pattern. Is that pattern a gradient, and the gradient is restarting in each section? Is it also incorrect at the edges of the top two cells in the other section? What final effect are you after? – jrturton May 31 '12 at 17:25
  • @jrturton the only thing that is custom on that page is the background. Which I'm setting with the following code in `initWithNibName`: `self.tableView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"GC_TestWeight-red-background.jpg"]];` – Gavin Miller May 31 '12 at 17:30
  • And is that image a gradient pattern, or a consistent shade? – jrturton May 31 '12 at 17:32
  • The final effect I'm after is a background image that sites behind the grouped cells. – Gavin Miller May 31 '12 at 17:34
  • Did you try these solutions http://stackoverflow.com/questions/400965/how-to-customize-the-background-border-colors-of-a-grouped-table-view – Dilip Rajkumar May 31 '12 at 17:44

1 Answers1

3

The table view is restarting the gradient behind each section, since it is just taking the colour you have given it.

Instead, use the backgroundView property of the table view - create an image view using your image, and set this as the background view, or create a UIView with background colour as you are doing above.

You will need to remove any code you have setting background colours elsewhere, and make sure your section header views either have clear backgrounds, or a contrasting background.

As a simple demonstration, I have created a grouped table view with its background colour set to clear, and the following code in viewDidLoad of the table view controller:

- (void)viewDidLoad
{
    [super viewDidLoad];

    UIView *backgroundView = [[UIView alloc] initWithFrame:self.tableView.bounds];
    CAGradientLayer *layer = [CAGradientLayer layer];
    layer.colors = [NSArray arrayWithObjects:(id)[UIColor redColor].CGColor,(id)[UIColor whiteColor].CGColor, nil];
    layer.frame = backgroundView.frame;
    [backgroundView.layer addSublayer:layer];
    self.tableView.backgroundView = backgroundView;
}

This gives the following (admittedly, pretty ugly!). The cells "float" on top of this.

enter image description here

jrturton
  • 118,105
  • 32
  • 252
  • 268