简体   繁体   English

将UILabel蒙版添加到UIVisualEffectView

[英]Add UILabel Mask to UIVisualEffectView

I have an UIImageView , UIVisualEffectView , and an UILabel on my ViewController . 我的ViewController上有一个UIImageViewUIVisualEffectView和一个UILabel The UIVisualEffectView blurs the UIImageView behind it. UIVisualEffectView使后面的UIImageView模糊。 I would like to mask the UIVisualEffectView with the text of the UILabel . 我想用UILabel的文本掩盖UIVisualEffectView Like this image: 喜欢这张图片:

在此处输入图片说明

How would I do this? 我该怎么做? I'm using Swift. 我正在使用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 您需要将UILabel分配为UIVisualEfectView的UIVisualEfectView ,技巧是需要为UIVisualEfectViewUILabel添加一个容器,并将该容器视图的背景色设置为UIColor.clear

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

View Hierarchy Setup 查看层次结构设置

在此处输入图片说明

Result 结果

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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