简体   繁体   English

如何使用 LaunchScreen.storyboard 添加渐变背景?

[英]How to add a gradient background with LaunchScreen.storyboard?

I want to add a gradient background to LaunchScreen.storyboard.我想为 LaunchScreen.storyboard 添加渐变背景。 Since this gradient changes with the diagonal of the screen, it is difficult for UIImageView to support screens with different aspect ratios.由于这个渐变随着屏幕对角线的变化而变化,所以 UIImageView 很难支持不同纵横比的屏幕。

So far, Launch Image was used to solve this.到目前为止,Launch Image 就是用来解决这个问题的。 However, Apple enforces the use of LaunchScreen.storyboard.但是,Apple 强制使用 LaunchScreen.storyboard。

How do I add this to LaunchScreen.storyboard?如何将其添加到 LaunchScreen.storyboard?

Thanks.谢谢。

在此处输入图片说明

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).然后,您可以将UIImageView添加到LaunchScreen.storyboard (内容模式:缩放以填充)。


Edit编辑

LaunchScreen storyboards cannot execute any code - and that includes trying to use a custom subclass. LaunchScreen 故事板不能执行任何代码——包括尝试使用自定义子类。

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: UIImageView - 包括在 LaunchScreen 中使用时 - 可以针对不同的大小特征使用不同的图像:

在此处输入图片说明

You cannot get down to actual screen sizes, but using different images for the different trait combinations might do the trick.您无法深入了解实际的屏幕尺寸,但对不同的特征组合使用不同的图像可能会奏效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM