2

I want to add a gradient background to LaunchScreen.storyboard. Since this gradient changes with the diagonal of the screen, it is difficult for UIImageView to support screens with different aspect ratios.

So far, Launch Image was used to solve this. However, Apple enforces the use of LaunchScreen.storyboard.

How do I add this to LaunchScreen.storyboard?

Thanks.

enter image description here

  • The launch screen interface is supposed to be static. You can't modify the launch screen in storybaord dynamiclly, you should implement a custom launch screen to achieve what you need – Mac3n Feb 12 '20 at 17:53
  • Does this answer your question? [Angled Gradient Layer](https://stackoverflow.com/questions/37038055/angled-gradient-layer) – ZGski Feb 12 '20 at 19:37
  • 1
    @ZGski As Mac3n says, LaunchScreen.storyboard cannot do this because it cannot execute custom code. –  Feb 13 '20 at 14:36

1 Answers1

3

Use an image editor (or whatever suits you) to create that as an image.

You can then add a UIImageView to your LaunchScreen.storyboard (Content Mode: Scale to Fill).


Edit

LaunchScreen storyboards cannot execute any code - and that includes trying to use a custom subclass.

If scaling a single image doesn't suit your needs, you do have a (limited) option.

UIImageView - including when used in a LaunchScreen - can have different images for different size traits:

enter image description here

You cannot get down to actual screen sizes, but using different images for the different trait combinations might do the trick.

DonMag
  • 69,424
  • 5
  • 50
  • 86
  • Thank you. This is effective for simple gradients, but cannot be used if the orientation of the gradient differs depending on the width and height of the screen. Does UIImageview have the option to have different images for different resolutions? This is an issue with LaunchScreen.storyboard where custom code is not available. –  Feb 13 '20 at 15:02
  • I have tried this with 2 : 1 aspect ratio image. This answer seems to work correctly. –  Feb 15 '20 at 03:21