简体   繁体   中英

How can I specify dark/light mode images for a slider in an iOS settings bundle?

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

灯光模式

Dark mode

深色模式

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

You can make do with one set of images for both modes of display if you use gray as foreground color. If you also apply a little transparency to the foreground then the page background will be able to show through, which makes the images slightly lighter for light mode and slightly darker for dark mode. I found that a gray shade close to #707070 and opacity 0.85 works quite well, see screenshots.

灯光模式 深色模式

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM