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

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

    Here's yet another approach, using just UI object calls:

    - (void)drawRect:(CGRect)rect
    {
        [[UIColor lightGrayColor] setFill];
        CGRect r2 = CGRectInset(rect, 10, 10);
        UIBezierPath* p = [UIBezierPath bezierPathWithRoundedRect:r2 cornerRadius:15];
        [p appendPath: [UIBezierPath bezierPathWithRect:rect]];
        p.usesEvenOddFillRule = YES;
        [p fill];
    }
    

    Yields this:

    enter image description here

    The white is the background of the window; the grey is the UIView. As you can see, we're seeing right thru the view to whatever is behind it, which sounds like what you're describing.

提交回复
热议问题