简体   繁体   中英

Add UILabel Mask to UIVisualEffectView

I have an UIImageView , UIVisualEffectView , and an UILabel on my ViewController . The UIVisualEffectView blurs the UIImageView behind it. I would like to mask the UIVisualEffectView with the text of the UILabel . Like this image:

在此处输入图片说明

How would I do this? I'm using Swift.

You need to assign your UILabel as maskView of your UIVisualEfectView and the trick is that you need add a container for your UIVisualEfectView and your UILabel and set the background color for this container view as UIColor.clear

self.visualEfectView.mask = self.label
self.visualEfectView.layer.masksToBounds = true

View Hierarchy Setup

在此处输入图片说明

Result

在此处输入图片说明

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