I am trying to have 3 text views and an image view inside a vstack and have them align differently.
Here is my code:
VStack(alignment: .leading) {
Text("This is the first paragraph").foregroundColor(Color.red)
Spacer().frame(height: 10)
Text("This is a paragraph with ").foregroundColor(Color.blue) + Text("multiple colors.").foregroundColor(Color.green)
Spacer().frame(height: 10)
if #available(iOS 15.0, *) {
AsyncImage(url: URL(string: "https://www.example.org/img/image.png")) { image in
image.resizable()
} placeholder: {
Color.red
}
.frame(width: 128, height: 128)
.clipShape(RoundedRectangle(cornerRadius: 25))
}
Spacer().frame(height: 10)
Text("Final paragraph").foregroundColor(Color.red)
Spacer()
}
Here in the below image I would like the first line and the image to be center aligned:

I tried it like below but then the left aligned text didn't leave a margin like the above image.
struct ContentView: View {
var body: some View {
VStack {
HStack {
Text("This is the first paragraph").foregroundColor(Color.red).frame(alignment: .leading)
}
Spacer().frame(height: 10)
HStack {
Text("This is a paragraph with ").foregroundColor(Color.blue) + Text("multiple colors.").foregroundColor(Color.green)
Spacer()
}
Spacer().frame(height: 10)
HStack {
if #available(iOS 15.0, *) {
AsyncImage(url: URL(string: "https://www.example.org/img/image.png")) { image in
image.resizable()
} placeholder: {
Color.red
}
.frame(width: 128, height: 128)
.clipShape(RoundedRectangle(cornerRadius: 25))
}
}
Spacer().frame(height: 10)
HStack {
Text("Final paragraph").foregroundColor(Color.red)
Spacer()
}
Spacer()
}
}
}


VStackwrapped most wide child view, so if your 2nd text will be wider there will be no "margin" anymore. So which layout you need at the end, eg. for any long text at 2nd line?