SwiftUI‘s shapes can be all consolidated in different ways to make new shapes, including association (a filled district blending the two shapes), crossing point (a filled locale containing areas normal in the two shapes), line convergence (returns the line of one shape covers the fill of another), and the sky is the limit from there.
For instance, this combine a circle with a capsule inset by 150, then fills the outcome blue:
Circle()
.union(.capsule.inset(by: 150))
.fill(.red)
We use the instance method union which returns a new shape with filled regions in either this shape or the given shape.
The benefit to having a solitary shape is that the outcome mixes well when you add mistiness – you’re not delivering two covering shapes separately, however consolidating them both into a solitary shape and delivering that.
Essentially, we could utilize lineSubtraction() to remove a square’s shape from a circle, then, at that point, stroke the rest of an adjusted cap:
Circle()
.lineSubtraction(.rect.inset(by: 20))
.stroke(style: .init(lineWidth: 30, lineCap: .round))
.padding()
The result in XCode will be:
Or on the other hand we could put one circle off to the left, then deduct one more circle offset to the right:
Circle()
.offset(x: -10)
.symmetricDifference(.circle.offset(x: 10))
.fill(.red)
.padding()