The rectangle that defines how the layer contents are scaled if the layer’s contents are resized. Animatable.
- iOS 3.0+
- macOS 10.6+
- tvOS 9.0+
- Core Animation
You can use this property to subdivide the layer’s content into a 3x3 grid. The value in this property specifies the location and size of the center rectangle in that grid. If the layer’s
contents property is set to one of the resizing modes, resizing the layer causes scaling to occur differently in each rectangle of the grid. The center rectangle is stretched in both dimensions, the top-center and bottom-center rectangles are stretched only horizontally, the left-center and right-center rectangles are stretched only vertically, and the four corner rectangles are not stretched at all. Therefore, you can use this technique to implement stretchable backgrounds or images using a three-part or nine-part image.
The value in this property is set to the unit rectangle
(0 by default, which causes the entire image to scale in both dimensions. If you specify a rectangle that extends outside the unit rectangle, the result is undefined. The rectangle you specify is applied only after the
contents property has been applied to the image.
By setting the layer's
(0, the button's corner radius remains unchanged, whatever size the layer is set to.
Figure 3 shows the layer at the same sizes but without explicitly setting the layer's
contents: the entire button image is scaled, including the rounded corners.