简体   繁体   中英

SWIFT - CALayer between PNG and background image

I have seen many stackoverflow posts or tutorials on how make a mask with an image and a rectangle or a circle, but it is possible to make a mask between a png file with transparency and a background image.

Photoshop中的蒙版

In the photoshop screenshot I use the wolf png image as a mask for the background.

Any approach for this with CALayer or other in SWIFT ?

Thank you very much.

UIView as of iOS 8 has a mask property which you can set to any view with an alpha channel, including a UIImageView that has your image in it.

This is just a wrapper arround CALayer's mask property which works similarly. Set your image to the content property of your masking layer and set the masking layer as the mask for your background image layer.

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