<!--
{
  "availability" : [
    "macOS: 10.9.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSView/clipsToBounds",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Property",
  "symbol" : {
    "kind" : "Instance Property",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(cs)NSView(py)clipsToBounds"
  },
  "title" : "clipsToBounds"
}
-->

# clipsToBounds

A Boolean value that indicates whether the view, and its subviews, confine their drawing areas to the bounds of the view.

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

## Discussion

Setting this value to <doc://com.apple.documentation/documentation/Swift/true> causes the view, and its subviews, to clip themselves to the bounds of the view. Setting it to <doc://com.apple.documentation/documentation/Swift/false> prevents views and subviews whose frames extend beyond the visible bounds of the view from clipping themselves. A value of <doc://com.apple.documentation/documentation/Swift/false> has no effect on [`hitTest(_:)`](/documentation/AppKit/NSView/hitTest(_:)) but does affect [`visibleRect`](/documentation/AppKit/NSView/visibleRect), as well as the area drawn inside [`draw(_:)`](/documentation/AppKit/NSView/draw(_:)).

By default this value is <doc://com.apple.documentation/documentation/Swift/false>. In macOS 13 and earlier, the default value is <doc://com.apple.documentation/documentation/Swift/true>.

Because of this change in default value, views built on macOS 13 and earlier may require layout adjustments such as the following on newer versions of macOS:

- Showing or hiding UI elements by setting a parent’s frame size to zero. To hide a view hierarchy by shrinking the parent view, or positioning a child view outside a parent’s bounds, set the [`clipsToBounds`](/documentation/AppKit/NSView/clipsToBounds) property of the parent view to <doc://com.apple.documentation/documentation/Swift/true>. Alternatively, set [`isHidden`](/documentation/AppKit/NSView/isHidden) to <doc://com.apple.documentation/documentation/Swift/true> on the parent view instead.
- Filling the `dirtyRect` of a view inside [`draw(_:)`](/documentation/AppKit/NSView/draw(_:)). It’s a common practice to set the background color on a view by calling [`setFill()`](/documentation/AppKit/NSColor/setFill()) on a background color and then calling <doc://com.apple.documentation/documentation/CoreFoundation/CGRect/fill(using:)> on the `dirtyRect` parameter passed into an override of [`draw(_:)`](/documentation/AppKit/NSView/draw(_:)). Because the `dirtyRect` now extends outside your view’s bounds, call <doc://com.apple.documentation/documentation/CoreFoundation/CGRect/fill(using:)> on the view’s bounds instead of the `dirtyRect`, or set the view’s [`clipsToBounds`](/documentation/AppKit/NSView/clipsToBounds) to <doc://com.apple.documentation/documentation/Swift/true>.
- Differentiating a view’s bounds from its `dirtyRect`. Use the `dirtyRect` parameter passed to [`draw(_:)`](/documentation/AppKit/NSView/draw(_:)) to determine what to draw, not where to draw it. Use the view’s [`bounds`](/documentation/AppKit/NSView/bounds) to determine the layout of what your view draws.

---

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)