Instance Property


A Boolean value that determines whether the view’s bounds should be automatically cleared before drawing.


var clearsContextBeforeDrawing: Bool { get set }


When set to true, the drawing buffer is automatically cleared to transparent black before the draw(_:) method is called. This behavior ensures that there are no visual artifacts left over when the view’s contents are redrawn. If the view’s isOpaque property is also set to true, the backgroundColor property of the view must not be nil or drawing errors may occur. The default value of this property is true.

If you set the value of this property to false, you are responsible for ensuring the contents of the view are drawn properly in your draw(_:) method. If your drawing code is already heavily optimized, setting this property is false can improve performance, especially during scrolling when only a portion of the view might need to be redrawn.