跳转至
Structure

ScaledShape

A shape with a scale transform applied to it.

Declaration

@frozen struct ScaledShape<Content> : Shape where Content : Shape

Overview

A scaled shape has two use cases:

  1. Used directly via its initializer, init(shape:scale:anchor:).
  2. As the return value of the scale(x:y:anchor:) and scale(_:anchor:).

Having a scaled shape is helpful because it allows you to scale a shape and then continue to use its shape properties, instead of turning into View.

A simple example of constructing a ScaledShape:

struct ContentView: View {
    let scale = CGSize(width: 0.5, height: 0.5)

    var body: some View {
        ScaledShape(shape: Rectangle(), scale: scale)
            .border(Color.orange)
            .padding()
    }
}
A screenshot displaying an orange rectangular border near the edges of the screen. Inset within this border is a black filled rectangle that is scaled down to half the size of its surrounding border by applying a 0.5 scale in the scaledShape initializer.

Availability

iOS 13.0+

macOS 10.15+

tvOS 13.0+

watchOS 6.0+

Topics


Initializer

init(shape:scale:anchor:) Creates a scaled shape from an original shape, a scale factor, and an anchor point.


Instance Property

anchor The unit point to scale the view from.

animatableData The data to animate.

scale The scale factor.

shape The original shape, before the scale.


Type Alias

AnimatableData The type defining the data to animate.

Body The type of view representing the body of this view.


Instance Method

path(in:) Describes this shape as a path within a rectangular frame of reference.