I use image, this image has two versions for light and dark UIUserInterfaceStyle
, but I need to use the image light version in one UIViewController
when Dark Mode is on. I know I can use tintColor
, but I want to find out if other ways to do this.
Asked
Active
Viewed 1,957 times
3

Alexander Khitev
- 6,417
- 13
- 59
- 115
2 Answers
7
Subramanian's answer is perfect for this use case.
However, I you really need just the UIImage
in a different style, you can do the following:
// create a trait collection with `light` interface style
let traitCollection = UITraitCollection(userInterfaceStyle: .light)
// If you have an existing image, you can change it's style like this:
let lightImage = image.withConfiguration(traitCollection.imageConfiguration)
// Or if you load the image by name, you can do this:
let lightImage = UIImage(named: "imageName", in: nil, compatibleWith: traitCollection)

Frank Rupprecht
- 9,191
- 31
- 56
1
You can opt out of dark mode for a particular view controller by setting the overrideUserInterfaceStyle property in viewDidLoad function. Sample snippet as follows.
override func viewDidLoad() {
super.viewDidLoad()
// Always adopt a light interface style.
overrideUserInterfaceStyle = .light
}
To opt out dark mode for your image view you can set as follows.
imageview. overrideUserInterfaceStyle = .light
You can check out further about opt out of dark mode from the link below. Hope it helps.

Subramanian Mariappan
- 3,736
- 1
- 14
- 29
-
No, I'm sorry I mean light version of the image, not UIViewController – Alexander Khitev Oct 22 '19 at 15:14
-
I have updated the answer. You can also set overrideUserInterfaceStyle of imageview to opt out of dark mode for the particular imageview. – Subramanian Mariappan Oct 22 '19 at 15:17