I think you're misunderstanding what the alignment parameter does in a VStack.
It aligns the subviews in the stack, not the stack itself.
Here's a visual example:
import SwiftUI
struct ContentView: View {
var body: some View {
VStack(alignment: .leading) {
Image(systemName: "arrow.2.circlepath")
.colorInvert()
.font(.system(size: 30))
.border(Color.yellow)
Text("alignment: .leading")
.font(.system(size: 20))
.foregroundStyle(Color.white)
.border(Color.yellow)
}
.frame(maxWidth: .infinity)
.background(Color.black)
VStack(alignment: .trailing) {
Image(systemName: "arrow.2.circlepath")
.colorInvert()
.font(.system(size: 30))
.border(Color.yellow)
Text("alignment: .trailing")
.font(.system(size: 20))
.foregroundStyle(Color.white)
.border(Color.yellow)
}
.frame(maxWidth: .infinity)
.background(Color.green)
HStack {
VStack(alignment: .leading) {
Image(systemName: "arrow.2.circlepath")
.colorInvert()
.font(.system(size: 30))
.border(Color.yellow)
Text("alignment: .leading in an HStack")
.font(.system(size: 20))
.foregroundStyle(Color.white)
.border(Color.yellow)
}
Spacer() // <<-- Remove this line and see the difference
}
.frame(maxWidth: .infinity)
.background(Color.blue)
}
}
#Preview {
ContentView()
}
In the blue section, where I've said to remove the line with the Spacer() this is to show you the effect of using an HStack, which is what I think you want.
The HStack simply lines up views horizontally, and when you add in a Spacer() it pushes the content along, so this pushes the text to the left:
|SOME TEXT HERE<---Spacer()--->|
This pushes the text to the right:
|<---Spacer()--->SOME TEXT HERE|
and this spreads it out:
|SOME<---Spacer()--->TEXT<---Spacer()--->HERE|