DarkMode - Magic, Method or Math?

I just recently decided to make the Swift app I am working on Dark Mode compatible.
And as far as those standard colors I was using, the conversion was fairly straight forward.

However, previous to this decision, I had created what I thought was a very nice “theme” based on gradients of blues and grays. This looks fine in light mode where tables and such are white. But looks totally wrong when tables and such are black.

So, is there some Magic, a method or some Math that can be used to take an RGB color value that would be used in Light Mode, and determine what a “best” color might be for Dark mode? I have examined all the Apple defined pairs, and can’t find a mathematical relationship, if there is one.

I dont believe there is
One thing that we discovered in Dark Mode for macOS, which may be similar on iOS, is that most things are not just raw solid colors but are colors composited with varying levels of alpha channel involved.
And then you get visual effect views thrown in and … yeehaw !!! (thats why the navigator has that bit of transparency)
That’s what took so damned long with the IDE and dark mode.

Yeah I noticed the “alpha” thing… Apple predefines some 30 odd system colors, and about 1/2 of them have a non 0xFF alpha value.

My app looks good (my opinion at least) in light mode, but trying to find a balance that also looks good in dark mode has proven more difficult than writing the app in the first place :slight_smile:

One site I read suggested “reduce the white by the value of the color”… but didn’t offer to explain what that actually meant

Yeah I’ve never found a decent algorithm that did convert from light to dark
We tried some of that for the IDE as well and finally just gave up
And that was about when the light mode color scheme changed as well since we started using the named colors (underpagebackground etc) instead of the hard coded light mode colors we had long used

In case anyone wants to know how to detect DarkMode in iOS …

public var darkMode : Bool {
    if #available(iOS 13, *) {
        if UITraitCollection.current.userInterfaceStyle == .dark { return true }
    return false // pre-iOS13 will always be false
1 Like