---
title: contentsGravity
framework: quartzcore
role: symbol
role_heading: Instance Property
path: quartzcore/calayer/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

Discussion The possible values for this property are listed in Contents Gravity Values. The default value of this property is 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. top, you should also check the layer’s contentsAreFlipped(). When this is true, top aligns contents to the bottom of the layer and 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. Figure 1 shows four examples of the effect of setting different values for a layer’s contentsGravity property.

Contents gravity is resize - the default Contents gravity is center Contents gravity is contentsAreFlipped() ? top : bottom Contents gravity is contentsAreFlipped() ? bottomLeft : topLeft

## See Also

### Modifying the layer’s appearance

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