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

后端 未结 5 943
星月不相逢
星月不相逢 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:58

    Add multiple subpaths to your context, and draw with mode kCGPathEOFill. The Quartz 2D Programming Guide explains in more detail.

    // Outer subpath: the whole rect
    CGContextAddRect(context, rrect);
    
    // Inner subpath: the area inside the whole rect    
    CGContextMoveToPoint(context, minx, midy);
    ...
    // Close the inner subpath
    CGContextClosePath(context);
    
    // Fill the path
    CGContextDrawPath(context, kCGPathEOFill);
    

提交回复
热议问题