这里也描述了我的问题 UIColor return wrong values for dark mode colors 通过李安德鲁
基本上没有正确选择按钮的边框颜色。在我的情况下是:
- 以白色模式打开 VC1。
- 在白色模式下插入 VC2。
- 在 VC2 中切换到深色模式。
- UI 已正确更新。
- 通过导航回到 VC1
按钮的边框没有正确更新。它使用白色模式的颜色,但是文本正确地改变了颜色。
上面列出的问题中提出的 layer.background 解决方案没有帮助...如果有帮助,则不使用 beta xcode 版本 11.0 (11A420a)。真的可以在这里使用帮助......我别无选择。为按钮调用 setNeedsDisplay 也无济于事。
更新。 解决了问题。直接调用按钮不起作用。但是,在我覆盖所有带有边框颜色按钮(单元格、页脚、页眉等)的 traitCollectionDidChange 方法之后 - 事情开始正常工作。
最佳答案
解决您的问题:
override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
super.traitCollectionDidChange(previousTraitCollection)
// Your custom borderColor
layer.borderColor = .white
}
Note: If you're using tableview/collectionview you have to set the color in the object and in the border "init" else only the visible cells will update the border color.
关于swift - 按钮边框没有为暗模式选择合适的颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58078061/