What I would like to achieve. regardless the width of text width at both side the button should always at the center of the HStack.
HStack {
Text("Foooooooo")
Spacer(minLength: 5)
Button(action: { }) {
Text("Bar")
}
Spacer()
Text("Baz")
}
.font(.system(size: 16, weight: .heavy, design: .rounded))
.padding()
I also tried to use GeometryReader and set frame size for each Text and Button in the view however there are two problems,
- The view returned by
GeometryReaderwould occupies the entire view the parent offers to it instead of the actual intrinsic content size, the space only enough forText,SpacerandButton - String inside the first
Textcould not be left align so does the string inside the lastTextcouldn't be right aligned


