Setting A CGContext Transparent Background

后端 未结 8 764
长发绾君心
长发绾君心 2020-12-08 09:15

I am still struggling with drawing a line with CGContext. I have actually go to line to draw, but now I need the background of the Rect to be transparent so the existing ba

8条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-08 09:49

    Easy way:

    - (id)initWithFrame:(CGRect)frame
    {
        if ((self = [super initWithFrame:frame]))
        {       
            self.opaque = NO;
        }
        return self;
    }
    
    - (void)drawRect:(CGRect)rect
    {
        CGContextRef context = UIGraphicsGetCurrentContext();
        CGContextClearRect(context, rect);
        //your code
    }
    

提交回复
热议问题