don
don

Reputation: 4542

Cell background not transparent

Searching thorugh some posts I have tried without success to set the background of some dynamically generated cells to transparent.

In the storyboard I have a prototype table, under which I have an image. In storyboard I have set alpha to 0.3 for the prototype table, so that the image is partially visible. It renders as desired.

The problem is that the cells add an extra layer of color, so that the image is still visible, but a little less (as if the alpha was 0.6 for example). Actually, it seems like there are three layers. The table, the cell (which darkens the bg a little) and then another small rectangle inside each row around the text (which darkens the bg even more).

I've edited the function that generates the cells like so (based on what I've understood from the threads on this topic):

NSString *cellIdentifier = @"ItemCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier];

cell.textLabel.text = [self.labels objectAtIndex:indexPath.row]; // gets the text of the cell from an array
cell.textLabel.textColor = [UIColor colorWithRed:0.80 green:0.80 blue:0.80 alpha:1.0];
UIView *backView = [[UIView alloc] initWithFrame:CGRectZero];
backView.backgroundColor = [UIColor clearColor];
// I've also trued with  = [UIColor colorWithRed:0. green:0 blue:0 alpha:0.0] 
cell.backgroundView = backView;

The problem is that I still get that extra layer.

Upvotes: 1

Views: 828

Answers (2)

Mohammad Kamar Shad
Mohammad Kamar Shad

Reputation: 6067

See, I have done changes somewhere in your code and try to use it.

[tableView setOpaque:NO];

NSString *cellIdentifier = @"ItemCell"; 
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
//if cell is already created then reuse it no need to create unnecessarily.
if(cell= nil){//otherwise create new cells.
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle  reuseIdentifier:cellIdentifier];
UIView *backView = [[UIView alloc] initWithFrame:CGRectZero];
backView.backgroundColor = [UIColor clearColor];
cell.backgroundView = backView;

  }

cell.textLabel.text = [self.labels objectAtIndex:indexPath.row]; 
cell.textLabel.textColor = [UIColor colorWithRed:0.80 green:0.80 blue:0.80 alpha:1.0];

Upvotes: 1

Ayush
Ayush

Reputation: 3999

[tableView setOpaque:NO];
[tableView setBackgroundColor:[UIColor clearColor]];

Upvotes: 0

Related Questions