How to mask the layer of a view by the content of another view?

心已入冬 提交于 2019-12-18 12:47:40

问题


I have a UIImageView and a UILabel, and want the content of the UILabel to mask the UIImageView. The goal is that the text is visible with content of image but everything else transparent.

Is there a simple way to mask a view by the contents of another view?


回答1:


You can use QuartzCore Framework.

(Link project with QuartzCore.framework and import <QuartzCore/QuartzCore.h>).

@import QuartzCore;

Background of label must be clear color. Example:

self.imageView.layer.mask = self.label.layer;
self.imageView.layer.masksToBounds = YES;

In Interface Builder:

On device:



来源:https://stackoverflow.com/questions/15998536/how-to-mask-the-layer-of-a-view-by-the-content-of-another-view

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!