Search code examples
ioscalayerquartz-graphicsmask

How to mask a CALayer with another CALayer which is transparent?


I only managed to do so If I set cornerRadius property to the layer I want to mask.

I am trying to achieve:

  1. UIView that is whole blue.
  2. CALayer with full background color red.
  3. maskLayer, CALayer which is smaller than the first one (CGRectInset(redLayer.frame, 20, 20))
  4. redLayer.mask = maskLayer
  5. [blueView.layer addSublayer:redLayer]

Now I would like to have only red border (redLayer) and middle would be blue (because blueView is blue). This blue part is size/shape of maskLayer (and is transparent so thats why I should see blue color).

Am I on a right track here?


Solution

  • maskLayer must have some color set on it.