Ask Your Question
4

How can I prevent the Launch Screen Image from stretching in SwiftUI?

asked 2023-02-17 11:00:00 +0000

nofretete gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2022-06-26 20:00:00 +0000

lalupa gravatar image

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.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-02-17 11:00:00 +0000

Seen: 15 times

Last updated: Jun 26 '22