skip to Main Content

I’m hoping I can get some help explaining why this is happening. I have been working on switching my app I’ve been learning / building from UIKit to SwitfUI since this seems to be the future… plus it’s fun to learn.

I’ve got my plist setup with the background and image
enter image description here

And the very first time I run it when the simulator opens or I clear and erase the simulator is this:
enter image description here

However, every time after I run the app, the image stretches.
enter image description here

When I try it on my phone, it seems to stretch every time. I’m not sure what is happening here. Is it just that SwiftUI needs more work or is there a setting I’m missing?

6

Answers


  1. Resize your image to @1x, @2x, and @3x versions when @1x is 200x200px.

    Then upload it to Assets folder and change info.plist Image Name.

    This worked for me.

    Login or Signup to reply.
  2. I have resolved the same issue with changing the dimensions of SVG.

    1. Select the Launch image from the assets and press the "Space" button.
    2. Open with Subline Text.
    3. Change width & Height ( I give the dimensions of iPhone 12 pro in px , initially it was 100%)

    <svg width="390px" height="844px" viewBox="0 0 1500 1500"

    Login or Signup to reply.
  3. I’ll mention this because it technically worked for me.

    Turn off the device. Turn it on again. Reinstall the app. Launch screen is not stretched anymore!

    It’s a strange behavior and it makes me wonder if it’s a bug with iOS and not with swiftui.

    I got this answer from a comment on this article.

    Login or Signup to reply.
  4. This seems to be a SwiftUI Bug, which still isn’t fixed. The only way to go around this bug is to go back to storyboards.

    You have to create a launch screen storyboard and link it to your project.

    To do so:

    • create a new file (cmd + n) and select launch screen
    • customize your launch screen inside the new storyboard (don’t use SVG format for images)
    • go to your project settings -> "General" and select the launch screen file as your “Launch Screen File”, which creates a new entry in your info.plist
    • remove your old SwiftUI launch screen entries in info.plist
    Login or Signup to reply.
  5. If you are using .svg images for the launch screen (works on device).

    1. In assets, select the image (in list) and select the image (in detail).
    2. Shows the inspector (button on the top right).
    3. In the Resizing option, check Preserve Vector Data.
    4. In the Scales option, select Single Scale.

    I hope it will be useful, to this recurring question and even today with Xcode 14 it is not really solved.

    Login or Signup to reply.
  6. This may help:

    1. In the attributes inspector check "Preserve Vector Data"
    2. In Scales select "Single Scale"

    It works for me.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search