UITableViewCell Background Color

I have a UITableViewController that I am trying to customize. I have 95% of the way, but it's hard for me to eliminate the strange shading from the background of the cell. I highlighted what I'm trying to remove in this screenshot:

Normal view

To try to solve this problem, I dropped all the views that make up my UITableView and then colored them to try to find the view I need to change:

Styled view

As you can see, I could not color this particular place. In other words, I can’t find a view related to this place.

How to remove this shading from my cells?

+4
source share
1 answer

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.

enter image description here

+3
source

Source: https://habr.com/ru/post/1415415/


All Articles