I'm new at SwiftUI, I'm trying this time to align right a single element (an image) to the right and then the rest of the content should be center aligned.
Just like what happens when you use Spacer()
on an HStack
but to the other side.
I read about .alignmentGuide
and it was a little bit confusing but I tried using it this way:
struct ContentView: View {
var body: some View {
VStack {
HStack {
Text("Hello!").alignmentGuide(.trailing) {
v in v[HorizontalAlignment.trailing]
}
}
Text("Hello, World!")
Spacer()
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
But this makes no change at all, both Text
are center aligned.
I tried moving the .alignmentGuide
code after the }
of the HStack
with the same result.
This is what I'm trying to do, before with storyboards I'd use some constraints to do this, like setting the right constraint to 8 or something, but I'm a bit lost when it comes to doing it the SwiftUI way.