简体   繁体   中英

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?

maskLayer必须设置一些颜色。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM