跳转至
Structure

Circle

A circle shape.

Declaration

@frozen struct Circle : Shape

Overview

A Circle is centered on the frame of the view containing it. The circle's radius equals half the length of the frame rectangle's smallest edge.

By default, a Circle is black, and takes up the space of its container:

struct ExampleView: View {
    var body: some View {
        Circle()
    }
}
A view containing a circle with default black fill.

Define a Circle with a specific color and frame with the Shape/fill() and View/frame(width:height:) modifiers. For example:

struct ExampleView: View {
    var body: some View {
        Circle()
            .fill(Color.blue)
            .frame(width: 200, height: 200)
    }
}
A view containing a blue filled circle with a frame of width 200 and height 200.

To add a border, use the Shape/stroke(:lineWidth:) modifier, and use the inset(by:) modifier to inset the circle by half of the border width to keep the circle at its original size:

struct ExampleView: View {
    var body: some View {
        Circle()
            .inset(by: 10)
            .stroke(Color.blue, lineWidth: 20)
    }
}
A view containing a circle inset by 10 with a blue strok of lineWidth 20.

Availability

iOS 13.0+

macOS 10.15+

tvOS 13.0+

watchOS 6.0+

Topics


Initializer

init() Creates a Circle that aligns itself inside of the view containing it by default.


Instance Method

inset(by:) Returns a Circle insetted by the amount specified.

path(in:) Used to describe a Circle as a path in a CGRect.


Type Alias

AnimatableData The type defining the data to animate.

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

InsetShape The type of the inset shape.