iPhone - Draw transparent rectangle on UIView to reveal view beneath

后端 未结 4 2098
醉酒成梦
醉酒成梦 2020-11-28 21:13

I currently have two UIViews: one of a red background and the other blue. The blue view is a subview of the red view. What I would like to do is be able to \"cut\" out rec

4条回答
  •  一个人的身影
    2020-11-28 21:43

    There is truth in all the other answers, but it is quite possible to draw with clear colour, or so to say erase the existing colours within any path, even with the -[UIBezierPath fill] or similar convenience methods. All you have to do is to set the context blend mode to an appropriate value depending on the effect you are trying to achieve, like so:

    CGContextSetBlendMode(context, kCGBlendModeClear);
    [[UIColor clearColor] set];
    [myArbitraryPolygonPath fill];
    

    There are around two dozen different options you could choose from, take a look around the CGContext reference.

提交回复
热议问题