<!--
{
  "availability" : [
    "iOS: 2.0.0 -",
    "iPadOS: 2.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.5.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "QuartzCore",
  "identifier" : "/documentation/QuartzCore/CALayer/contentsGravity",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Property",
  "symbol" : {
    "kind" : "Instance Property",
    "modules" : [
      "Core Animation"
    ],
    "preciseIdentifier" : "c:objc(cs)CALayer(py)contentsGravity"
  },
  "title" : "contentsGravity"
}
-->

# contentsGravity

A constant that specifies how the layer’s contents are positioned or scaled within its bounds.

```
var contentsGravity: CALayerContentsGravity { get set }
```

## Discussion

The possible values for this property are listed in [Contents Gravity Values](/documentation/QuartzCore/contents-gravity-values).

The default value of this property is [`resize`](/documentation/QuartzCore/CALayerContentsGravity/resize).

> Important:
> The naming of contents gravity constants is based on the direction of the vertical axis.  If you are using gravity constants with a vertical component, e.g. ``doc://com.apple.quartzcore/documentation/QuartzCore/CALayerContentsGravity/top``, you should also check the layer’s ``doc://com.apple.quartzcore/documentation/QuartzCore/CALayer/contentsAreFlipped()``. When this is <doc://com.apple.documentation/documentation/Swift/true>, ``doc://com.apple.quartzcore/documentation/QuartzCore/CALayerContentsGravity/top`` aligns contents to the bottom of the layer and ``doc://com.apple.quartzcore/documentation/QuartzCore/CALayerContentsGravity/bottom`` aligns content to the top of the layer.
> 
> The default coordinate system for views in macOS and iOS differ in the orientation of the vertical axis: in macOS, the default coordinate system has its origin at the lower left of the drawing area and positive values extend up from it, and in iOS the default coordinate system has its origin at the upper left of the drawing area and positive values extend down from it.
> 
> For more information, see [Coordinate system](https://developer.apple.com/library/content/documentation/General/Conceptual/Devpedia-CocoaApp/CoordinateSystem.html).

[Figure 1](/documentation/quartzcore/calayer/1410872-contentsgravity#2851774) shows four examples of the effect of setting different values for a layer’s [`contentsGravity`](/documentation/QuartzCore/CALayer/contentsGravity) property.

![Different effects of setting a layer’s contents gravity](images/com.apple.quartzcore/media-2851774@2x.png)

1. Contents gravity is [`resize`](/documentation/QuartzCore/CALayerContentsGravity/resize) - the default
2. Contents gravity is [`center`](/documentation/QuartzCore/CALayerContentsGravity/center)
3. Contents gravity is [`contentsAreFlipped()`](/documentation/QuartzCore/CALayer/contentsAreFlipped()) `?` [`top`](/documentation/QuartzCore/CALayerContentsGravity/top) : [`bottom`](/documentation/QuartzCore/CALayerContentsGravity/bottom)
4. Contents gravity is [`contentsAreFlipped()`](/documentation/QuartzCore/CALayer/contentsAreFlipped()) `?` [`bottomLeft`](/documentation/QuartzCore/CALayerContentsGravity/bottomLeft) : [`topLeft`](/documentation/QuartzCore/CALayerContentsGravity/topLeft)

---

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)