-1

In SwiftUI when a horizontal array of Circles are made like this:

HStack(spacing : 4) {
  Foreach(0..<5) { index in
    Circle()
  }
}

How the (horizontal) spacing value of 4 is applied? Is it between the centre of two circles or from their edges instead?

Paulo Mattos
  • 18,845
  • 10
  • 77
  • 85
Ae Ri
  • 185
  • 1
  • 12
  • 2
    The `spacing` is *between* view frames (nothing about internals, like center, etc.) – Asperi Jan 01 '22 at 12:16
  • 1
    Did you run this code? It's quite clear when you see it in action. – EmilioPelaez Jan 03 '22 at 00:05
  • Yes. I tried it with just two circles . In the editor canvs guidelines appeared at the outer points. But I got different results when I used this for calculation. (Total length = length of line + half the radii of two circles) – Ae Ri Jan 03 '22 at 16:52

1 Answers1

2

Building on top of @Asperi's comment: the spacing is applied in the same way it's applied to Text or Button standard views, which is between the frames of the views.

If you click on an element in the preview (this doesn't work when on live preview mode), you can see the frame of an element outlined in blue. The spacing is applied between the edges of the frames of each view.

Paulo Mattos
  • 18,845
  • 10
  • 77
  • 85
Stoic
  • 945
  • 12
  • 22