Optimization Opportunity: Use a container layer instead of mask with background color

Hello,

At RunTime I'm being suggested an Optimization Opportunity for some code I've written.

The layer is using a simple layer with background color set as a mask. Instead, use a container layer of the same "frame" and "cornerRadius" as the mask, but with "masksToBounds" set to YES

I'm afraid I don't know what is meant here by a "container layer". This is the code that threw up the optimization opportunity

     let maskView = UIView(frame: CGRect(x: 0, y: 0, width: 45, height: 90))
    maskView.backgroundColor = .black
    filledImage.mask = maskView

The code above masks half of a 90x90 UIImageView filledImage. Any ideas how this could be refactoring to use a "container layer".

Many thanks

That means instead of using a mask, just use a superlayer or superview to do your clipping instead. So instead of creating a mask view and setting it as a mask on the other view, just add the other view as a subview.

Optimization Opportunity: Use a container layer instead of mask with background color
 
 
Q