iOS 13 DarkMode和LaunchScreen-适用于iOS 10的后备 [英] iOS 13 DarkMode and LaunchScreen - Fallback for iOS 10

查看:74
本文介绍了iOS 13 DarkMode和LaunchScreen-适用于iOS 10的后备的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在白色背景上的launchscreen.storyboard上有一个蓝色徽标. 对于iOS 13引入的新DarkMode,我想反转颜色,即蓝色背景和白色徽标.

I have a blue logo on the launchscreen.storyboard on white background. For the new DarkMode introduced with iOS 13 I like to invert the colors, i.e. blue background and white logo.

我们知道,可以使用资产目录中的命名颜色来完成此操作,颜色会根据设备的特性而变化. 在iOS 11及更高版本中,此功能完全可以正常工作,但在尝试支持iOS 10时显示此错误:

As we know this can be done using named colors from the asset catalogues, which change depending on the traits of the device. This is working totally fine in iOS 11 and up but shows this error when trying to support iOS 10:

Named colors do not work prior to iOS 11.0.

我尝试用代码为启动屏幕场景制作一个视图控制器,并使用#ifavailable子句在那里设置颜色,但是编译器说启动屏幕可能没有与之关联的自定义类.

I tried making a view controller for the launchscreen scene in code and set the colors there using the #ifavailable clause, but the compiler says a launchscreen may not have a custom class associated with it.

我还考虑过根据iOS版本使用不同的启动屏幕情节提要,但找不到任何方法.

I also thought of using different launchscreen storyboards depending on the iOS version but I couldn't find anything about how to.

我能做些什么吗? 如何解决这个问题?

Anything I can do about it? How to solve this problem?

谢谢, 费利克斯

推荐答案

根据此处的建议,解决方案是使用而是使用动态图片作为背景:

As suggested here, the solution is to use a dynamic image for the background instead:

  1. 为浅色和深色模式创建2张具有纯色的图像.
  2. 将它们导入资产目录"并定义任何"/深色"外观.
  3. 在启动屏幕的背景中添加带有此图像的"UIImageView"(缩放至填充",限于容器).
  1. Create 2 images with the flat colors for light and dark mode.
  2. Import them in your Asset Catalog and define the "Any"/"Dark" appearances.
  3. Add a UIImageView in the background of your Launch Screen with this image ("Scale to Fill", constrained to container).

即使您的部署目标低于iOS 11.0,它也会编译,并在启动时显示适当的颜色.

This will compile even if your deployment target is lower than iOS 11.0, and will display the appropriate color at launch.

这篇关于iOS 13 DarkMode和LaunchScreen-适用于iOS 10的后备的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆