iOS13适配相关

  • Post author:
  • Post category:其他




Dark Mode 暗黑模式简介

官方文档:

In iOS 13.0 and later, people can choose to adopt a dark system-wide appearance called Dark Mode. In Dark Mode, the system uses a darker color palette for all screens, views, menus, and controls, and it uses more vibrancy to make foreground content stand out against the darker backgrounds. Dark Mode supports all accessibility features.

在iOS 13.0或更高版本中,人们可以选择采用一种名为dark Mode的全系统暗模式。在暗模式下,系统对所有屏幕、视图、菜单和控件使用较暗的调色板,并使用更多的活力使前景内容在较暗的背景中脱颖而出。暗模式支持所有可访问性特性。



关闭APP的暗黑模式

iOS13更新后可能需要对UI进行相应的适配,那么开发者很关心的一个问题,如何在APP UI中关闭暗黑模式呢。

很简单,在Info.plist文件中添加Key:User Interface Style,值类型设置为String,值为Light,重新运行项目就OK了。

在这里插入图片描述



暗黑模式下导航栏标题颜色修改

切换到暗黑模式(Dark Mode)下导航栏标题会变成白色,可以用如下代码修改颜色。

[self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor redColor],NSFontAttributeName:[UIFont systemFontOfSize:17]}];

在这里插入图片描述



控件的背景颜色

官方文档中描述:

When you use the system-defined materials, your elements look great in every context, because these effects automatically adapt to the system’s light and dark modes.

当您使用系统定义的材料时,您的元素在任何上下文中看起来都很棒,因为这些效果会自动适应系统的亮模式和暗模式。

在暗黑模式下,开发中必须指定控件的颜色,如单元格的背景色,字体的颜色等,如果使用系统默认颜色,切换到暗黑模式下背景颜色会变成黑色或字体会变成白色,影响展示的可能性很大。

在这里插入图片描述



隐藏导航栏底部边框

Human Interface Guidelines 中提到:

Consider hiding the border of a large-title navigation bar. In iOS 13 and later, you can hide the bottom border of a navigation bar by removing the bar’s shadow (the border automatically reappears when people scroll the content area).

我们可以利用到的就是:

在iOS 13或更高版本中,你可以通过移除导航栏的阴影来隐藏导航栏的底部边框(当用户滚动内容区域时,边框会自动重新出现)。

 [self.navigationController.navigationBar setShadowImage: [[UIImage alloc] init]];

在这里插入图片描述



版权声明:本文为ILOVEIT954原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。