3

My problem was also described here UIColor return wrong values for dark mode colors by Lee Andrew

Basically border color for buttons is not being picked properly. In my case scenario is:

  1. Open VC1 in white mode.
  2. Push VC2 in white mode.
  3. Switch to dark mode in VC2.
  4. UI updated correctly.
  5. Moving back through navigation to VC1

Button's border there was not updated properly. It was using color for white mode, text however changed color properly.

Solution for layer.background proposed in question listed above doesn't help... using not beta xcode Version 11.0 (11A420a) if that helps. Can really use help here... I'm out of options. Calling setNeedsDisplay for button doesn't help either.

Update. Got the thing sorted out. Direct call of the button didn't work. However after I've overrided traitCollectionDidChange method on everything with button with border color (cells, footer, header, etc) - thing begin to work properly.

Alexander
  • 396
  • 1
  • 11
  • Sadly - no :( Currently thinking to use transparent image for background of button with lines to emulate that layer border color. – Alexander Sep 24 '19 at 10:23
  • Can you show the code where you tried the said solution? – Rakesha Shastri Sep 24 '19 at 10:28
  • Did you override `traitCollectionDidChange` and re-set the button's border color then? Since `borderColor` is a property of the layer, it doesn't update automatically when the appearance change. – Frank Rupprecht Sep 24 '19 at 11:10
  • Yeah. Everything is in traitCollectionDidChange. Works normally if I am on a VC and change modes. – Alexander Sep 24 '19 at 12:21

1 Answers1

1

To solve your problem:

    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.

Thiago Valente
  • 673
  • 8
  • 25