iOS Solid text over a background image and low alpha cell background

67 Views Asked by At

How do I get the text in my cells to show as solid text while still fading the cell background so I can see the image behind?

I have the following in my ViewController: `

- (void)viewDidLoad {
    // Used to see the background image
    self.tableView.backgroundColor = [UIColor clearColor];
    self.tableView.backgroundView = [[UIImageView alloc] initWithImage:[UIImage    imageNamed:@"background.png"]];
    self.tableView.backgroundView.contentMode = UIViewContentModeScaleAspectFill;
}

-(void) tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *) cell forRowAtIndexPath:(NSIndexPath *)indexPath { 
    cell.alpha=0.5; 
    cell.textLabel.alpha=1.0; 
}

The result is shown in the image where the background image can be seen through the text and cell background. I only want to see the image through the cell background and have the text solid.

Is there a way to set the text to have an alpha of 1.0 while the background is 0.5?

app screenshot

1

There are 1 best solutions below

3
DonMag On

You can put this either in cellForRowAtIndexPath or willDisplayCell:

cell.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.5];

Output:

enter image description here

Set the label text color as you normally would (in cellForRowAtIndexPath), and adjust the colorWithAlphaComponent:0.5 to suit your needs.