---
title: clearsContextBeforeDrawing
framework: uikit
role: symbol
role_heading: Instance Property
path: uikit/uiview/clearscontextbeforedrawing
---

# clearsContextBeforeDrawing

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

## Declaration

```swift
var clearsContextBeforeDrawing: Bool { get set }
```

## Discussion

Discussion 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.

## See Also

### Configuring a view’s visual appearance

- [backgroundColor](uikit/uiview/backgroundcolor.md)
- [isHidden](uikit/uiview/ishidden.md)
- [alpha](uikit/uiview/alpha.md)
- [isOpaque](uikit/uiview/isopaque.md)
- [tintColor](uikit/uiview/tintcolor.md)
- [tintAdjustmentMode](uikit/uiview/tintadjustmentmode-swift.property.md)
- [clipsToBounds](uikit/uiview/clipstobounds.md)
- [mask](uikit/uiview/mask.md)
- [layerClass](uikit/uiview/layerclass.md)
- [layer](uikit/uiview/layer.md)
