<!--
{
  "availability" : [
    "iOS: -",
    "iPadOS: -",
    "macCatalyst: -",
    "tvOS: -",
    "visionOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "UIKit",
  "identifier" : "/documentation/UIKit/UIView/clearsContextBeforeDrawing",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Property",
  "symbol" : {
    "kind" : "Instance Property",
    "modules" : [
      "UIKit"
    ],
    "preciseIdentifier" : "c:objc(cs)UIView(py)clearsContextBeforeDrawing"
  },
  "title" : "clearsContextBeforeDrawing"
}
-->

# clearsContextBeforeDrawing

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

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

## Discussion

When set to <doc://com.apple.documentation/documentation/Swift/true>, the drawing buffer is automatically cleared to transparent black before the [`draw(_:)`](/documentation/UIKit/UIView/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`](/documentation/UIKit/UIView/isOpaque) property is also set to <doc://com.apple.documentation/documentation/Swift/true>, the [`backgroundColor`](/documentation/UIKit/UIView/backgroundColor) property of the view must not be `nil` or drawing errors may occur. The default value of this property is <doc://com.apple.documentation/documentation/Swift/true>.

If you set the value of this property to <doc://com.apple.documentation/documentation/Swift/false>, you are responsible for ensuring the contents of the view are drawn properly in your [`draw(_:)`](/documentation/UIKit/UIView/draw(_:)) method. If your drawing code is already heavily optimized, setting this property is <doc://com.apple.documentation/documentation/Swift/false> can improve performance, especially during scrolling when only a portion of the view might need to be redrawn.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)