24

How would you apply a background gradient to a launch screen file?

Are you supposed to just include large image for the background or can you run code in a launch screen file to do custom drawing?

Berry Blue
  • 15,330
  • 18
  • 62
  • 113

2 Answers2

14

You cannot run code or use any custom classes in the Launch Screen.

You'll have to supply a stretchable image, which contains enough data for it to be viable in all resolutions.

Also, you could take advantage of the @2x and @3x modifiers. iPhone 6 plus will try to load a @3x modifier, AFAIK.

As a last resort, if the Launch Screen xib is not enough for you, you could still use the UILaunchImages plist key, and specify images for minimum version of 8.0. The downside is that Xcode does not automatically generate those for you, so you'll have to write those manually. Also remember that the modifier for iPhone 6 plus images is @3x

An example:

UILaunchImage = Default // This is for iOS 6, if you need it

UILaunchImages // iOS 7, 8
- [0]
-   UILaunchImageName = Default
-   UILaunchImageMinimumOSVersion = 7.0
-   UILaunchImageSize = {320, 480}
-   UILaunchImageOrientation = Portrait
- [1]
-   UILaunchImageName = Default-568h
-   UILaunchImageMinimumOSVersion = 7.0
-   UILaunchImageSize = {320, 568}
-   UILaunchImageOrientation = Portrait
- [2]
-   UILaunchImageName = Default-667h
-   UILaunchImageMinimumOSVersion = 8.0
-   UILaunchImageSize = {375, 667}
-   UILaunchImageOrientation = Portrait
- [3]
-   UILaunchImageName = Default-736h
-   UILaunchImageMinimumOSVersion = 8.0
-   UILaunchImageSize = {414, 736}
-   UILaunchImageOrientation = Portrait

P.S. The plist above is also a perfect solution for those who are struggling with the localization of Image Catalogs or Launch Screen files.

daniel.gindi
  • 3,457
  • 1
  • 30
  • 36
10

As long as you can add PDF single vector assets to your projects, I usually export gradients that have to be in launch image from Illustrator or Photoshop to PDF and include them in the layout with pretty good results.

txuslee
  • 416
  • 3
  • 5
  • 1
    This works but is tricky to make it show up: I had to clear Xcode cache, restart Xcode, delete the app from the phone, restart the phone, and only then the image showed up... – lenooh Oct 30 '18 at 18:56
  • I needed to include the gradient in an Asset Catalog (and assign it to 1x, 2x, 3x) for this to work properly. I'm curious if Xcode converts the vector to a bitmap PNG at this point, however. – avance Dec 05 '18 at 21:44
  • You can also select "Single Scale" in "Scales" in the Attributes Inspector to avoid assigning it to 1x, 2x and 3x. And you can check the "Preserve Vector Data" box to ensure it scales well. See [here](https://useyourloaf.com/blog/xcode-9-vector-images) – Binary Pulsar Jan 23 '19 at 09:58
  • @lenooh What worked for me was just to close Xcode and reopen it. – Eric33187 Apr 08 '21 at 18:39