1 year ago

#211806

test-img

user717452

Add a blur effect for image behind a UITableView

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

ios

objective-c

uitableview

uiblureffect

0 Answers

Your Answer

Accepted video resources