Imagine this scenario:
- You obtained a custom shape path (for instance like this), but one of the default shapes will do as well.
- You want to draw the outline of that shape, with a
lineWidththat depends on some@Statevariable - The outline must grow externally so that even when it gets too big, it doesn't lose its contour's shape
- The inner fill is possibly transparent, for what matters.
So, I can't use strokeBorder<S>(_ content: S, lineWidth: CGFloat = 1) since its outline is centered on the actual contour of the path, as per documentation.
Also can't use stroke<S>(_ content: S, lineWidth: CGFloat = 1) (documentation here) since the effect is apparently just about the same, the outline is drawn centered.
An example code snippet reproducing the issue is the following:
struct ContentView: View {
@State private var outlineSize: CGFloat = 1
var body: some View {
VStack {
Circle()
.stroke(.red, lineWidth: self.outlineSize)
.frame(width: 100, height: 100)
Slider(value: self.$outlineSize, in: 1...10)
}
}
}
What about adding an overlay to the circle where the overlay contains the border?
Another solution would be to adjust the frame of the circle, but this changes the behaviour slightly where the circle frame expands and affects other views.