I have a custom UIView in which I implement several convenient drawing methods, allowing me to set corner radius of specific corners, draw borders, and use gradients instead of a background color. I achieve this by overriding drawRect(rect:CGRect)
. However, despite using CGContextClip
to clip drawing to the CGPathRef I generate, the background color is always drawn to fill the view's bounds. That is because the view's layer draws before drawRect is called.
Aside from overriding the setter for backgroundColor, are there any other ways to only draw what I am specifying in drawRect? I DO NOT want to mask the layer with a CAShapeLayer or something of the sort. It should still be possible to subclass and draw outside of the layer's bounds.
backgroundColor
to clear color and override the setter. That's the only thing you can do. Also note propertyclearsContextBeforeDrawing
andopaque
. – Sulthan