如何通过另一个视图的内容屏蔽视图层?

时间:2013-04-14 11:25:50

标签: ios uiview uiimageview calayer

我有一个UIImageView和一个UILabel,并希望UILabel的内容能够掩盖UIImageView。目标是文本在图像内容中可见,但其他一切都是透明的。

是否有一种简单的方法可以通过另一个视图的内容屏蔽视图?

1 个答案:

答案 0 :(得分:9)

您可以使用QuartzCore Framework

(使用QuartzCore.framework链接项目并导入< QuartzCore / QuartzCore.h>)。

@import QuartzCore;

标签背景必须是清晰的颜色。例如:

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

在Interface Builder中:

enter image description here

在设备上:

enter image description here