当设备上已经启用了暗模式并且我打开我的应用程序时,所有指定暗模式的颜色集都不会被应用:
但是当应用已经打开并从Control Center切换到黑暗模式时,以下代码会更改颜色:
override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
super.traitCollectionDidChange(previousTraitCollection)
guard let previousTraitCollection = previousTraitCollection else {return}
if #available(iOS 13.0, *) {
if previousTraitCollection.hasDifferentColorAppearance(comparedTo: traitCollection) {
//Dark Mode
let inputBackground = UIColor(named: "TEST1backgroundColor")
let inputPlaceholder = UIColor(named: "TEST1placeholderColor")
passwordBack.layer.backgroundColor = inputBackground?.cgColor
TextField1.placeholderColor = inputPlaceholder!
TextField2.placeholderColor = inputPlaceholder!
TextField1.textColor = inputPlaceholder!
TextField2.textColor = inputPlaceholder!
}
}
}
在已经处于黑暗模式下启动时如何应用这种颜色更改?