黑暗模式的适配其实很简单, 下面就讲一种最简单的场景, 无需增加代码。
首先创建颜色和图片。 这里的颜色和图片有两种情况进行设置,分别对应的就是黑暗和白天模式

颜色:

图片:

颜色和图片都配置好了,如何使用呢
let imageView = UIImageView(image: UIImage(named: "Image"))
imageView.frame = .init(x: 200, y: 200, width: 200, height: 200)
view.addSubview(imageView)
view.backgroundColor = UIColor(named: "test_1")
效果:
模拟器模式的切换

白天模式:

黑夜模式:

网友评论