Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Launch Screen Image Stretches in SwiftUI

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?

like image 814
Jason Brady Avatar asked Jan 19 '21 03:01

Jason Brady


People also ask

How do I set launch screen?

If your project doesn't contain a default launch screen file, add a launch screen file and set the launch screen file for the target in the project editor. Choose File > New > File. Under User Interface, select Launch Screen, and click Next.

What is LaunchScreen storyboard?

It's the replacement for launch images. The main storyboard is what your app actually displays when the app is running. It contains your app, code, and logic. Follow this answer to receive notifications.


Video Answer


2 Answers

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.

like image 53
SwiftyLifestyle Avatar answered Sep 23 '22 07:09

SwiftyLifestyle


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.

As described in this blog post, 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
like image 30
Tom Hakemann Avatar answered Sep 19 '22 07:09

Tom Hakemann