The view of the table restarts the gradient behind each section, since it just takes on the color that you gave it.
Instead, use the backgroundView
property in the table view — create an image view using your image and set it as a background view or create a UIView with the background color, as you do above.
You will need to remove any code that you set as the background of the background elsewhere, and make sure that the section headings have clear backgrounds or a contrasting background.
As a simple demonstration, I created a grouped table view with the background color set on it and the following code in the viewDidLoad
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 (true, pretty ugly!). Cells float on top of this.
source share