As you can see, the Image in the background of the Spacer is overlapping with the next element of the VStack, the TextField. Also, the image should fill the width while keeping its aspect ratio, and can't clip the bottom of the image. The overflow should be pushed to the top.
How can I align the image to the exact bottom of the Spacer?
That fixes bottom overlay issue, but is because is using .fit as contentMode.
I need to use .fill to full the width of the Spacer(). With .fit adds a padding on both sides of the container.
That was my initial approach, but what happens is that the image is always at the top and all new context is appended below and causing an overflow at the botttom. What I'm trying to achieve is the opposite.
Have to mention that wrapping your code into a ScrollView and then using a ScrollReader to scroll to the bottom when view appears does the trick, but I wanted to avoid the use of ScrollView if possible, since I found some incompatibilities in the past when dissabling the scroll.
Edit (suggestion removed): Sorry, I misread the issue you had.
In the future you might want to ask this kind of question about SwiftUI (the framework, not the Swift language) over on the apple developer forums where it has more visibility to people who have more experience with Apple frameworks. You might not find many people that can help you with SwiftUI on these forums.
The thing about Spacer() is it doesn’t really have an area. You can see this by adding
Spacer()
.border(.yellow)
The spacer does its job but there’s no yellow border. Instead you have to force a dimension perpendicular to the direction it’s spacing
Spacer()
.frame(width: 30)
.border(.yellow)
and then the yellow appears.
The next thing is using GeometryReader to size things out the full width. GeometryReader should be a tool of last resort and in your example it isn’t needed, instead use this to make things full width
.frame(maxWidth: .infinity)
That’ll push a view outwards/bigger until other views say no more. You can get rid of the GeometryReader and use that instead on your VStacks. And on the Spacer too so it actually fills all that area
Now that there’s a correct frame we add the background and use the backgrounds alignment option to position its subview (I’m not sure if adding the alignment on the Images frame does anything). So here’s a final Spacer that does what I think you’re after
Note that the unwanted portion of the Image is conveniently pushed up and/or to the sides of the Spacers frame because of the bottom alignment. But in the case you wanted the Image to be centered then add clipShape to the Spacer to restrict the Image to the Spacers frame