/// a custom shape
struct BlobShape: Shape {
func path(in rect: CGRect) -> Path {
Path { path in
// `CGRect` conforms to `Rectangular` protocol,
// which has `rect[x,y]` subscript method.
path.move(to: rect[0.5, 0])
path.addCurve(to: rect[1.0, 0.5], control1: rect[1.0, 0.0], control2: rect[1.0, 0.0])
path.addCurve(to: rect[0.5, 1.0], control1: rect[0.5, 0.5], control2: rect[1.0, 1.0])
path.addCurve(to: rect[0.0, 0.5], control1: rect[0.0, 1.0], control2: rect[0.5, 0.5])
path.addCurve(to: rect[0.5, 0.0], control1: rect[0.0, 0.0], control2: rect[0.0, 0.0])
path.closeSubpath()
}
}
}
/// a view containing a custom shape
struct BlobView: View {
var body: some View {
BlobShape()
.outlined( // ๐Shape+ext
fill: .linearGradient(
colors : [.yellow, .green, .blue],
startPoint: .topLeading,
endPoint : .bottomTrailing
),
strokeStyle: .init(lineWidth: 10)
)
.frame(width: 300, height: 300)
}
}