0% found this document useful (0 votes)
2 views

Rectangle

The document describes how to create a Rectangle as a path within a specific CGRect using the Rectangle/path(in:) modifier in SwiftUI. It provides code examples demonstrating how to align a Rectangle inside its containing view. Additionally, it mentions that Swift infers the view type from the implementation of the required body property when creating a custom view.

Uploaded by

jon.moses2000
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Rectangle

The document describes how to create a Rectangle as a path within a specific CGRect using the Rectangle/path(in:) modifier in SwiftUI. It provides code examples demonstrating how to align a Rectangle inside its containing view. Additionally, it mentions that Swift infers the view type from the implementation of the required body property when creating a custom view.

Uploaded by

jon.moses2000
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

Used to describe a Rectangle as a path in a `CGRect`.

A Rectangle can be described as a path within a specific


[`CGRect`](https://developer.apple.com/documentation/coregraphics/cgrect) using
the ``Rectangle/path(in:)`` modifier:

![Rectangle path example](rectangle-example-3.png)

```
struct ExampleView: View {
var body: some View {
Rectangle()
.path(in: CGRect(x: 0, y: 0, width: 100, height: 100))
}
}
```
Creates a Rectangle that aligns itself inside of the view containing it
by default.

```
struct ExampleView: View {
var body: some View {
Rectangle()
}
}
```

![A screenshot displaying a black filled rectangle that occupies the


entire screen; since no frame is set, the rectangle aligns itself inside
of its containing view by default, which renders as a black screen.]
(rectangle-example-4.png)
The type defining the data to animate.
The type of view representing the body of this view.

When you create a custom view, Swift infers this type from your
implementation of the required `body` property.

You might also like