简体   繁体   English

为深色或浅色模式启动图像

[英]Launch Images for Dark or Light Mode

有谁知道我如何为暗模式或亮模式选择一组不同的启动图像?

As the Launch Screen loads before the app starts executing, it would not be possible to change the launch images set programatically.由于启动屏幕在应用程序开始执行之前加载,因此无法以编程方式更改启动图像设置。

However, in the Image Set tab, you can change the Appearance option to enable a different set of images for Light and Dark modes:但是,在“ Image Set选项卡中,您可以更改“ Appearance选项以启用不同的明暗模式图像集:

在此处输入图片说明

So, if you set this image in the Launch Screen Storyboard, the result would be as below:因此,如果您在 Launch Screen Storyboard 中设置此图像,结果将如下所示:

在此处输入图片说明

On a side note, if the need is just to change the background color, not the images, you may set the Launch Screen Storyboard view background color to System Background Color and just use transparent .png images.附带说明一下,如果只需要更改背景颜色,而不是图像,您可以将 Launch Screen Storyboard 视图背景颜色设置为System Background Color并仅使用透明的 .png 图像。

  1. Xcode 11 supports only storyboard Launch screen files. Xcode 11 仅支持情节提要启动屏幕文件。 It means I should to use storyboards.这意味着我应该使用故事板。
  2. In storyboards we can use UIImageViews + images from .xcassets.在故事板中,我们可以使用 UIImageViews + .xcassets 中的图像。 Assets support images with different variants: Light, Dark modes.资产支持具有不同变体的图像:浅色、深色模式。 You can apply constraints for positioning them on screen.您可以应用约束来在屏幕上定位它们。
  3. If you support iOS before 11.0 you can not use system dynamic colors for backgrounds of the screen view.如果您支持 11.0 之前的 iOS,则不能将系统动态颜色用于屏幕视图的背景。 In this case you put additional dynamic image to screen as background and apply leading, trailing, top and bottom constraints with negative values.在这种情况下,您将额外的动态图像作为背景放置在屏幕上,并使用负值应用前导、尾随、顶部和底部约束。 Negative values are needed for covering Top and Bottom Bars.覆盖顶柱和底柱需要负值。 (I used -64px) (我使用了 -64px)

You need to add dark appearance for your asset, or for the asset color you are using, like in the image below:您需要为您的资产或您正在使用的资产颜色添加深色外观,如下图所示:

在此处输入图片说明

This WWDC'19 session gives an introduction to Dark Mode, the principles behind it, and tips on how to add support for it in an app. 这个WWDC'19 会议介绍了暗模式,它背后的原理,以及如何在应用程序中添加对它的支持的提示。

If you start somewhere at 10:10, you'll get an idea of how to implement launch images for dark and light mode. 如果你从10:10开始某个地方,你就会知道如何为暗和亮模式实现启动图像。

You should do something like this to use light and dark mode images你应该做这样的事情来使用明暗模式的图像

  1. Step 1 - Create image set in assets.xassets like this第 1 步 - 在 assets.xassets 中像这样创建图像集在此处输入图片说明

  2. Step 2 - Select Image select like this第 2 步 - 像这样选择图像选择

在此处输入图片说明

  1. Steps 3 - Change appearance to Any, Light , Dark like this步骤 3 - 像这样将外观更改为 Any, Light , Dark 在此处输入图片说明

在此处输入图片说明

  1. Add your images for any light and dark mode like this and use this image wherever you need it为任何这样的明暗模式添加图像,并在任何需要的地方使用此图像

在此处输入图片说明

仅就我的经验而言,有时当您擦除应用程序、关闭设备并再次打开时,启动图像会发生变化。

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

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