Infinity Width Pushes Frame Off Screen

Viewed 27

Basically I have a picture that is supposed to stretch the entire width of the screen, but when I fix the width to infinity - it pushes the frame width off the screen - like shown below.

enter image description here

Minimum Reproducible Code

import SwiftUI

struct ItemView: View {
    var body: some View {
        ZStack {
            
            //Grey background color
            Color(red: 0.9, green: 0.9, blue: 0.9).edgesIgnoringSafeArea(.all)
            
            
            VStack {
                
                Image("PS5")
                    .resizable()
                    .aspectRatio(contentMode: .fill)
                    .frame(width: .infinity, height: 250)

 
                Spacer()
            }
        }
        .ignoresSafeArea()
        .navigationBarTitleDisplayMode(.inline)
        
    }
}

struct ItemView_Previews: PreviewProvider {
    static var previews: some View {
        ItemView()
    }
}
1 Answers

... follow-up on comments - just delete .aspectRatio(contentMode: .fill) to have

Image("PS5")
    .resizable()
    .frame(height: 250)
Related