1 | initial version |
You can prevent the Launch Screen Image from stretching in SwiftUI by setting the scaling mode to "aspectFit". Here's how:
Open your "Xcode" project and go to your "Assets.xcassets" folder.
Click on "AppIcon & LaunchImage" folder.
Select "LaunchImage" from the right-side panel.
Click on "Render As" dropdown and select "Aspect Fill" option.
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()
}
}
}
.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.