UIView drawRect: Draw the inverted pixels, make a hole, a window, negative space

后端 未结 5 932
星月不相逢
星月不相逢 2020-12-10 09:04

With the code below I am drawing a rounded rectangle. It draws a nice solid light gray filled rounded rectangle (at the size of \"self\"). I actually want to draw the pixel

5条回答
  •  离开以前
    2020-12-10 09:53

    Another approach: use UICreateGraphicsContextWithOptions(size, NO, 0) to make a bitmap. Draw the rectangle into the bitmap. Switch to the erasure blend mode:

    CGContextSetBlendMode(con, kCGBlendModeClear);
    

    Now draw the ellipse path and fill it. The result is a rectangle with a transparent elliptical hole. Now close out the image graphics context and draw the image into your original context.

提交回复
热议问题