Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITableView cell takes pattern color of UITableView's background image

I've added custom background image to my UITableView and it shows fine. Than, i removed any background color from the cells. Now i expect to see only cells' text on top of table's background image, however i see strange behaviour. Cells take pattern color of table's background image, so that i see waves like in the picture:

enter image description here

The background image shell look like this:

enter image description here

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

My code is as follws: in viewDidLoad i set the background image of table view:

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

For each cell i remove any background color like this:

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.
like image 341
Misha Avatar asked Jun 27 '11 05:06

Misha


1 Answers

Instead of setting the BackgroundColor attribute of 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 issue of the cell's taking on the same image as the background.

like image 190
Ethan Mick Avatar answered Oct 05 '22 22:10

Ethan Mick