How to handle black colored content image for dark mode in my iOS App?

Viewed 4105

I am giving support for iOS dark mode in my iPad App throughly. The issue is only for dark mode when brand logo image is having black color. Generally, all brand logo are never white colored, so there is no issue for light mode.

Here are the screenshot for both the modes:

Adura brand logo in Light mode

enter image description here

Adura brand logo in Dark mode

enter image description here

How can I accommodate such logos? I got few suggestion to set background view behind the logo with gray color, but again some brand might come having gray colored logo.

2 Answers

Here sample code:

// Somewhere where you set UIImage for UIImageView
let imageView = UIImage()
let image = UIImage(named: "img.png")?.withRenderingMode(.alwaysTemplate)
imageView.image = image
imageView.tintColor = .black
...

override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
        super.traitCollectionDidChange(previousTraitCollection)
        if traitCollection.userInterfaceStyle == .dark {
            imageView.tintColor = .red
        }
        else {
            imageView.tintColor = .black
        }
    }

This worked for me

  1. Step 1 - Create image set in assets.xassets like this enter image description here

  2. Step 2 - Select Image select like this

enter image description here

  1. Steps 3 - Change appearance to Any, Light , Dark like this enter image description here

enter image description here

  1. Add your images for any light and dark mode like this and use this image wherever you need it

enter image description here

Related