Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Buttons border don't pick proper color for dark mode

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.

like image 267
Alexander Avatar asked Nov 21 '25 11:11

Alexander


1 Answers

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.

like image 82
Thiago Valente Avatar answered Nov 23 '25 03:11

Thiago Valente