Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SwiftUI Image in ZStack not aligning to bottom of screen

Tags:

swift

swiftui

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

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

like image 519
Derek Avatar asked Dec 06 '25 17:12

Derek


1 Answers

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))
like image 97
Asperi Avatar answered Dec 10 '25 01:12

Asperi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!