---
title: contentsGravity
framework: Core Animation
role: symbol
role_heading: Instance Property
platforms: [iOS 2.0+, iPadOS 2.0+, Mac Catalyst 13.1+, macOS 10.5+, tvOS 9.0+, visionOS 1.0+]
path: quartzcore/calayer/1410872-contentsgravity
---

# contentsGravity

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

## Declaration

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

## Discussion

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

The default value of this property is [resize](../calayercontentsgravity/resize.md).

> **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. [top](../calayercontentsgravity/top.md), you should also check the layer’s [contentsAreFlipped()](contentsareflipped().md). When this is [true](../../swift/true.md), [top](../calayercontentsgravity/top.md) aligns contents to the bottom of the layer and [bottom](../calayercontentsgravity/bottom.md) 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`.

[Figure 1](1410872-contentsgravity.md) shows four examples of the effect of setting different values for a layer’s [contentsGravity](contentsgravity.md) property.

![]()

1. Contents gravity is [resize](../calayercontentsgravity/resize.md) - the default
2. Contents gravity is [center](../calayercontentsgravity/center.md)
3. Contents gravity is [contentsAreFlipped()](contentsareflipped().md) `?` [top](../calayercontentsgravity/top.md) : [bottom](../calayercontentsgravity/bottom.md)
4. Contents gravity is [contentsAreFlipped()](contentsareflipped().md) `?` [bottomLeft](../calayercontentsgravity/bottomleft.md) : [topLeft](../calayercontentsgravity/topleft.md)

## See Also

### Modifying the layer’s appearance

- [Contents Gravity Values](../contents-gravity-values.md)
- [opacity](opacity.md)
- [isHidden](ishidden.md)
- [masksToBounds](maskstobounds.md)
- [mask](mask.md)
- [isDoubleSided](isdoublesided.md)
- [cornerRadius](cornerradius.md)
- [maskedCorners](maskedcorners.md)
- [CACornerMask](../cacornermask.md)
- [borderWidth](borderwidth.md)
- [borderColor](bordercolor.md)
- [backgroundColor](backgroundcolor.md)
- [shadowOpacity](shadowopacity.md)
- [shadowRadius](shadowradius.md)
- [shadowOffset](shadowoffset.md)
