UITableView cell displays UITableView background color

I added a custom background image to my UITableView and it looks great. Than I removed any background color from the cells. Now I expect to see the text of only cells on top of the background image of the table, however, I see strange behavior. The cells take the color pattern of the background image of the table, so that I can see the waves, as in the picture:

enter image description here

The shell of the background image is as follows:

enter image description here

* Pay attention to the white circles that disappear under the cells!

My code is as follows: in viewDidLoad I sets the background image of the table view:

self.tableView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"general_bg.png"]]; 

For each cell, I remove any background color as follows:

 UIView *bckView = [[[UIView alloc] initWithFrame:CGRectZero] autorelease]; bckView.backgroundColor = [UIColor clearColor]; cell.backgroundView = bckView; cell.backgoundColor = [UIColor clearColor]; cell.contentView.backgroundColor = [UIColor clearColor]; UILabel *textLabel = [[UILabel alloc] initWithFrame:CGRectMake(x,y,x1,y1)]; textLabel.backgroundColor = [UIColor clearColor]; [cell.contentView addSubview:textLabel]; 
  • line separators are custom images added to cells.
+6
source share
2 answers

Instead of setting the BackgroundColor attribute in the tableview, try setting the backgroundview:

 UIView *background = [[UIView alloc] initWithFrame:self.tableView.bounds]; background.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"YOUR_IMAGE.png"]]; self.tableView.backgroundView = background; 

This should fix the problem with a cell accepting the same image as the background.

+13
source
 self.tableView.backgroundView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"YOUR_IMAGE.png"]]; 

perhaps this is what you are looking for

0
source

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


All Articles