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

后端 未结 1 860
太阳男子
太阳男子 2020-12-30 16:59

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 el

1条回答
  •  南方客
    南方客 (楼主)
    2020-12-30 17:39

    You can use QuartzCore Framework.

    (Link project with QuartzCore.framework and import ).

    @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:

    enter image description here

    On device:

    enter image description here

    0 讨论(0)
提交回复
热议问题