0

I have a UIView that has an image for the background view, and a TableView that sits on about half of the view. What I'd like to happen is have the table view and its cells completely transparent, but blur the image behind the table view so that it is still readable, but allows the image to be viewable. I have the following code in viewDidLoad, but everything behind the tableview is simply gray.

self.tableView.backgroundColor = [UIColor clearColor];

    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    UIGraphicsBeginImageContext(self.view.frame.size);
    [[UIImage imageNamed:@"ML Honeycomb.png"] drawInRect:self.view.bounds];
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    self.view.backgroundColor = [UIColor colorWithPatternImage:image];
    
    UIVisualEffect *effect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleProminent];
    UIVisualEffectView *blurEffectView = [[UIVisualEffectView alloc] initWithEffect:effect];
    self.tableView.backgroundView = blurEffectView;

In the cellForRowAtIndexPath I have made sure that all is clear:

static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
    }
    
        // Set up the cell...
        cell.textLabel.text = [arryData objectAtIndex:indexPath.section];
        cell.textLabel.font = [UIFont fontWithName:@"Roboto-Bold" size:22];
        cell.textLabel.textColor = [UIColor whiteColor];
        cell.detailTextLabel.numberOfLines = 0;
       
        cell.textLabel.backgroundColor = [UIColor blueColor];
        CALayer * m = [cell.textLabel layer];
              [m setMasksToBounds:YES];
              [m setCornerRadius:11];
              [m setBorderWidth:2.0];
              [m setBorderColor:[[UIColor whiteColor] CGColor]];
        
       
                cell.detailTextLabel.font = [UIFont fontWithName:@"Roboto-Bold" size:16];
                
               
                    cell.detailTextLabel.textColor = [UIColor whiteColor];
        
        
      
        
       

        NSString *thearticleImage = [[arryData objectAtIndex:indexPath.section] stringByAppendingString:@".png"];
        cell.imageView.image = [UIImage imageNamed:thearticleImage];
        cell.backgroundColor = [UIColor clearColor];
        return cell;

What I get is this: enter image description here

user717452
  • 33
  • 14
  • 73
  • 149
  • Did you set: `self.tableView.backgroundColor = [UIColor clearColor];` ? – DonMag Feb 22 '22 at 16:33
  • @DonMag Yes, it's the very first line of the code I posted – user717452 Feb 22 '22 at 16:51
  • hmmm.... your code is working fine for me. In the image you posted, is the pattern above the table view a separate image view? Or is it the pattern image you gave for the view's background color? If you *don't* set `tableView.backgroundView` is your table clear? – DonMag Feb 22 '22 at 17:20

0 Answers0