0

I have a slider in my settings bundle, using the PSSliderSpecifier type. I use the MinimumValueImage and MaximumValueImage keys to provide images that appear to the left/right of the slider. However, as seen in the screenshots below, those images do not adjust based on light/dark mode.

How can I specify a different image to be used, or a different tint color, in light/dark mode? All of the sliders in Apple's settings seem to adjust based on the mode, so it feels like there should be a way, but I don't see any documentation of how to make this happen.

Light mode

Light mode

Dark mode

Dark mode

Chris Vasselli
  • 13,064
  • 4
  • 46
  • 49
  • 1
    Can you use images in asset catalogs? Then maybe setting the Rendering Mode to "Template Image" would work. – Frank Rupprecht Dec 03 '19 at 08:38
  • Yeah, that's a good idea. I tried both referring to an asset catalog in my main app bundle, and one embedded in the settings bundle itself. I've tried a bunch of different seemingly logical ways to refer to these images, but none seem to work. The only way I've gotten an image to appear from within the asset catalog is to specify a path directly to the image file itself (e.g., `SettingsImages.xcassets/Slow.imageset/Turtle.png`), which ignores the whole asset catalog metadata itself, so it doesn't actually accomplish anything. =( – Chris Vasselli Dec 03 '19 at 13:44
  • Oh, interesting... With all the shortcomings of iOS 13, I wouldn't be surprised if they just forgot about those images... – Frank Rupprecht Dec 03 '19 at 13:53
  • Starting to think that. Looking through the apps on my phone, very few people seem to use them. – Chris Vasselli Dec 03 '19 at 13:55
  • Maybe there's a magic file prefix like `@2x` or `~ipad` that works for dark mode? Couldn't find any, though... – Frank Rupprecht Dec 03 '19 at 13:57

2 Answers2

1

You can make do with one set of images for both modes of display if you use a medium shade of gray as foreground color. I found that #707070 works quite well, see below.

Light mode Dark mode

Benzy Neez
  • 1,546
  • 2
  • 3
  • 10
  • In fact it looks like the device settings might be doing it this way too, using systemGray (=#8e8e93) as the shade of gray. – Benzy Neez Jan 25 '23 at 15:18
0

well. first you can detect the dark mode

override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
    if traitCollection.userInterfaceStyle == .light {
        print("Light mode")
    } else {
        print("Dark mode")
    }
}

and you can custom the slider with his properties

 slider.minimumTrackTintColor = .green
 slider.maximumTrackTintColor = .red
 slider.thumbTintColor = .black

and the icons for volume you can change when your detect any userInterfaceStyle

Andres Gomez
  • 458
  • 3
  • 12
  • Sorry if it was unclear, but this is for a slider in a settings bundle. So, the settings that appear in the Settings app. I don't have the ability to run any code in that context. – Chris Vasselli Dec 03 '19 at 02:54