ios单应用模式_如何为iOS 13暗模式设置应用

ios单应用模式

Apple launched the much-awaited iOS 13 updates globally on September 19 across all iPhones launched within the past 4 years (back to the iPhone 6s).

苹果于9月19日在全球发布了期待已久的iOS 13更新,该更新适用于过去4年内发布的所有iPhone(返回iPhone 6s)。

One of the biggest features of this update was the system-wide iOS 13 dark mode. It's expected to help with eye-strain caused by white light emitted by smartphone displays.
此更新的最大功能之一是系统范围的iOS 13暗模式。 它有望帮助缓解由智能手机显示屏发出的白光引起的眼睛疲劳。

While this feature is a joy to end-consumers using Apple devices, it's a task for iOS developers to prepare an app ready for iOS 13 dark mode.

虽然此功能对于使用Apple设备的最终用户而言是一种乐趣,但iOS开发人员的任务是准备可用于iOS 13暗模式的应用程序。

如何为iOS 13黑暗模式设置您的应用程序? (How to Set up your App for iOS 13 Dark Mode?)

To help developers with this issue, here is useful info and steps showing how they can prep up an existing iOS app for iOS 13 dark mode.

为帮助开发人员解决此问题,此处提供了有用的信息和步骤,显示了他们如何为iOS 13暗模式准备现有的iOS应用。

  • It’s not too hard to implement iOS 13 dark mode despite its system-wide scale.

    尽管它具有系统范围的规模,但实现iOS 13黑暗模式并不难。
  • Enabling iOS 13 dark mode on your existing app is also simple mostly thanks to the latest iOS 13 SDK.

    由于最新的iOS 13 SDK,在现有应用程序上启用iOS 13暗模式也很简单。

When using the latest version to build apps for iOS 13 dark mode, the OS will automatically update switches, buttons, and table views among other system controls. Though do note that images and text colors won’t adjust for dark mode automatically.

使用最新版本为iOS 13暗模式构建应用程序时,操作系统将自动更新其他系统控件中的开关,按钮和表格视图。 不过请注意,图片和文字颜色不会自动调整为暗模式。

However, it’s still amazing to see that a system-wide change such as dark mode is so easy to implement. There are smaller code changes and more work that you'll be able to get done with the iOS 13 dark mode in that saved time.

但是,令人惊奇的是,系统范围的更改(如暗模式)如此容易实现。 在节省的时间内,使用iOS 13暗模式可以进行更小的代码更改和更多的工作。

如何为iOS 13深色模式调整颜色 (How to Adapt Colors For iOS 13 Dark Mode)

First, let’s start with changing system colors iOS 13 dark mode:

首先,让我们从更改系统颜色iOS 13暗模式开始:

Now there are new system colors added in UIColor, one of which is a label color. Using these new colors helps support dark mode and other high contrast modes in iOS 13.

现在,UIColor中添加了新的系统颜色,其中一种是标签颜色。 使用这些新颜色有助于在iOS 13中支持暗模式和其他高对比度模式。

label.color = UIColor.secondaryLabel

Generally, you should use system colors for iOS 13 dark mode, which automatically adapts to changes in the interface for maintaining consistency across apps. However, developers can also choose to implement dark mode with custom colors.

通常,您应该为iOS 13深色模式使用系统颜色,该颜色会自动适应界面更改,以保持应用程序之间的一致性。 但是,开发人员还可以选择使用自定义颜色实现暗模式。

The asset catalog colors introduced with iOS 11 make it much easier to support dark mode by adding dark versions of a custom set of colors.
通过添加自定义颜色组的深色版本,iOS 11引入的资产目录颜色使支持深色模式更加容易。

You only have to select a preferred color from the catalog, then change Appearances to Any, Dark from the Attributes Inspector.

您只需从目录中选择一种首选颜色,然后从“属性”检查器中将“外观”更改为“任意,深色”。

That's it! Now you have a custom iOS 13 dark mode ready for your mobile app.

而已! 现在,您已经为移动应用程序准备了自定义iOS 13暗模式。

对iOS 13暗模式进行故障排除 (Troubleshooting iOS 13 Dark Mode )

Let's say your app is not following iOS 13 dark mode. What will you do? Here are some easy steps to solve this issue.

假设您的应用未遵循iOS 13暗模式。 你会怎么做? 以下是解决此问题的一些简单步骤。

第1步 (Step 1)

You will need to know if the app is updated or not.

您将需要知道该应用程序是否已更新。

If the app is not working with iOS 13 Dark Mode or does not support it, simply update the app via Apple Store.

如果该应用程序无法在iOS 13暗模式下使用或不支持它,只需通过Apple Store更新该应用程序。

第2步 (Step 2 )

Check whether the Dark Mode of your iOS app has been enabled or not.

检查您的iOS应用的黑暗模式是否已启用。

If not, go to Settings - Display & Brightness - check whether "Dark" is enabled or not.

如果不是,请转到设置-显示和亮度-检查是否启用了“暗”。

第三步 (Step 3  )

If your app is fully updated, but isn't working with iOS 13 Dark Mode, then check the in-app settings. See the image:

如果您的应用程序已完全更新,但不能在iOS 13暗模式下使用,请检查应用程序内设置。 见图片:

If you want more help on setting up your iOS 13 Dark Mode, get it from the dedicated development teams. And, that is how I'm going to help you.

如果您需要更多有关设置iOS 13暗模式的帮助,请从专门的开发团队获得 。 而且,这就是我将如何帮助您。

Also read tips for mobile app development on iOS. Hope all this information will be helpful for you.

另请阅读有关在iOS上进行移动应用开发的提示。 希望所有这些信息对您有所帮助。

Let's see what you have to do next.

让我们看看您接下来要做什么。

为iOS 13暗模式调整图像 (Adapt Images For iOS 13 Dark Mode)

Most images look great in iOS 13 dark mode, and at times they pop out in a way that really highlights details. However, you may still end up finding some images which look a bit off or unsuitable for dark mode.

大多数图像在iOS 13暗模式下看起来很棒,有时会以突出显示细节的方式弹出。 但是,您仍然可能最终会发现一些看起来有些偏离或不适合黑暗模式的图像。

The good news is that you can adjust images for dark mode in the same way text is adjusted.
好消息是,您可以以调整文本的相同方式将图像调整为暗模式。

All you need to do is select the image in the catalog and as done previously, and change attributes to Any, Dark in the Attributes Inspector. Now add the dark appearance of the image and we’re done.

您需要做的就是选择目录中的图像,并像以前一样进行操作,然后在“属性”检查器中将属性更改为“任意,黑暗”。 现在添加图像的深色外观,我们完成了。

以编程方式在iOS 13暗模式下检测更改 (Programmatically Detecting Changes in iOS 13 Dark Mode)

Developers could face situations where they need to implement appearance changes in iOS 13 dark mode programmatically. This is how it's done:

开发人员可能会遇到需要以编程方式在iOS 13暗模式下实现外观更改的情况。 这是这样做的:

override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) 
{
    super.traitCollectionDidChange(previousTraitCollection)

    let userInterfaceStyle = traitCollection.userInterfaceStyle // Either .unspecified, .light, or .dark
    // Update your user interface based on the appearance
}
Overriding traitCollectionDidChange helps in detecting appearance changes.
覆盖traitCollectionDidChange有助于检测外观变化。
Then we only have to open traitCollection.userInterfaceStyle.
然后,我们只需要打开traitCollection.userInterfaceStyle。

You can also verify if the existing appearance is using a new method you just implemented:

您还可以验证现有外观是否正在使用刚实现的新方法:

override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
    super.traitCollectionDidChange(previousTraitCollection)

    let hasUserInterfaceStyleChanged = previousTraitCollection.hasDifferentColorAppearance(comparedTo: traitCollection) // Bool
    // Update your user interface based on the appearance
}

覆盖用户界面样式 (Overriding the User Interface Style)

完整的应用程序 (Complete App)

The system automatically opts-in any app linked against the iOS 13.0 or later SDK to both light and dark appearances.

系统会自动选择将与iOS 13.0或更高版本的SDK链接的任何应用程序显示为浅色和深色。

If you need extra time to work on your app’s Dark Mode support or want to keep your app in a single style, you can opt-out by including the UIUserInterfaceStyle key (with a value of Light or Dark) in your app’s Info.plist file.

如果您需要更多时间来处理应用程序的“暗模式”支持,或者希望使应用保持单一样式,则可以通过在应用的Info.plist文件中包含UIUserInterfaceStyle键(值为Light或Dark)来选择退出。

Setting this key causes the system to ignore the user’s preference and always apply the specific appearance to your app.

设置此键会导致系统忽略用户的偏好,并始终将特定外观应用于您的应用。

Note: Supporting iOS 13 Dark Mode is strongly encouraged. Use the UI UserInterfaceStyle key to opt-out only temporarily while you work on improvements to your app’s Dark Mode support.

注意:强烈建议支持iOS 13黑暗模式。 在改进应用程序的暗模式支持时,请使用UI UserInterfaceStyle键仅暂时退出。

特定画面 (Specific Screens)

In iOS 13, you can now override the user interface style on specific views or view controllers. For example, you may want only a certain view controller to be in iOS 13 dark mode, while the rest of your app is in light mode.

在iOS 13中,您现在可以在特定视图或视图控制器上覆盖用户界面样式。 例如,您可能只希望某个视图控制器处于iOS 13暗模式,而其他应用程序处于亮模式。

To override the user interface style, just override this variable in the top view or view controller and it will propagate down to sub-views:

要覆盖用户界面样式,只需在顶视图或视图控制器中覆盖此变量,它将向下传播到子视图:

// Inside a UIViewController
override func viewDidLoad() 
{
    super.viewDidLoad()

    // Always adopt a dark interface style.    
    overrideUserInterfaceStyle = .dark
}

结束语 (Closing Notes)

Thanks for reading the article! Here we've explored how to set up an app for iOS 13 dark mode.

感谢您阅读本文! 在这里,我们探讨了如何为iOS 13暗模式设置应用。

iOS 13 dark mode brings with it a unique stress-free way to use a smartphone. Perhaps we’ll see a future where dark mode replaces the default mode with the whiter backgrounds.

iOS 13黑暗模式带来了独特的无压力使用智能手机的方式。 也许我们会看到黑暗模式将默认模式替换为白色背景的未来。

By following these coding guidelines and tips you can easily set up your app for dark mode on iOS 13.

通过遵循这些编码准则和提示,您可以轻松地在iOS 13上将应用设置为暗模式。

If you need some expert help, feel free to get in touch with iOS developers for iOS 13 dark mode related queries.  

如果您需要一些专家帮助,请随时与iOS开发人员 联系以进行有关iOS 13暗模式的查询。

Follow on Twitter for more updates: https://twitter.com/ValueCoders

在Twitter上关注以获取更多更新: https //twitter.com/ValueCoders

翻译自: https://www.freecodecamp.org/news/how-to-setup-an-app-for-dark-mode-on-ios-13-untitled/

ios单应用模式

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值