Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

SwiftUI Image in ZStack not aligning to bottom of screen

I have this code

struct ContentView: View {
    var body: some View {
        ZStack(alignment:.bottom) {
            Image("login-devices-mobile")
                .resizable()
                .scaledToFit()
            
        }.padding(0.0).background(Image("login-background").aspectRatio(contentMode: ContentMode.fill))
    }
}

which I am trying to display an image on the bottom of the screen. However when I run the preview. It still shows in the middle.

Preview

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Any tips on anything I can do differently to align the image on the bottom of the screen?

>Solution :

I assume you wanted this

ZStack(alignment:.bottom) {
    Image("login-devices-mobile")
        .resizable()
        .scaledToFit()
    
}
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .bottom) // << here !!
.background(Image("login-background").aspectRatio(contentMode: ContentMode.fill))
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading