Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

You can prevent the Launch Screen Image from stretching in SwiftUI by setting the scaling mode to "aspectFit". Here's how:

  1. Open your "Xcode" project and go to your "Assets.xcassets" folder.

  2. Click on "AppIcon & LaunchImage" folder.

  3. Select "LaunchImage" from the right-side panel.

  4. Click on "Render As" dropdown and select "Aspect Fill" option.

  5. In the code, create a ZStack with the background color of your choice and add an Image view as shown below.

struct ContentView: View {
    var body: some View {
        ZStack {
            Color.blue
            Image("launchImage")
                .resizable()
                .scaledToFit()
        }
    }
}
  1. The .scaledToFit() modifier ensures that the Launch Screen Image does not stretch and is displayed with its original aspect ratio.

Now, the Launch Screen Image will be displayed without stretching in your SwiftUI app.