swift - 按钮边框没有为暗模式选择合适的颜色

标签 swift swift4.2 ios-darkmode

这里也描述了我的问题 UIColor return wrong values for dark mode colors 通过李安德鲁

基本上没有正确选择按钮的边框颜色。在我的情况下是:

  1. 以白色模式打开 VC1。
  2. 在白色模式下插入 VC2。
  3. 在 VC2 中切换到深色模式。
  4. UI 已正确更新。
  5. 通过导航回到 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/

相关文章:

swift - 如何在 Swift 中将文本字段输入限制在一定范围内的数字

ios - 使用 UITableView 和 CollectionView 进行布局

ios - 我想在键盘显示时更改 View 的框架

ios - 为什么我的应用程序在与计算机 iPhone 断开连接的情况下加载 MapKit View 时崩溃?

ios - Xcode 11,暗/亮图像的 Assets 目录命名约定?

swift - 对成员 'close()' 的引用不明确

ios - 应用程序退出后,在本地通知点击时推送 View Controller

swift - 图像压缩而不改变图像的分辨率

ios - iOS 13 是否可以选择退出深色模式?