6

I'm implementing the dark mode for iOS. The problem occurs with the images:

  • I've opened the Assets.xcassets and changed the "appearances" "to Any, Dark"
  • Of course I've added the new image.

Unfortunately the images are not being redrawn when overriding the environment interface style in xcode.

I've tried catching the traitCollectionDidChange method in my viewController and it is properly called. I could set the new image (origImage_dark), but shouldn't it be automatic? That's what the asset settings are made for. I'm using the .alwaysOriginal rendering of the image.

izik461
  • 1,131
  • 12
  • 32

1 Answers1

7

Running the app with dynamic resolve of the image helped:

let image = UIImage(named: "someImage")
let asset = image?.imageAsset
let resolvedImage = asset?.image(with: traitCollection)

After this, reverting back to the original way of setting the images seemed to work. Xcode, thanks a lot!

izik461
  • 1,131
  • 12
  • 32
  • How are you displaying the image? If you put it in a `UIImageView` it should automatically display the correctly resolved image. If you are drawing it yourself, then yes you will need to resolve it manually. – Kurt Revis Aug 14 '19 at 06:01
  • 2
    It was mostly in UIImageView and in controls (like UIButton.image). I'm now resolving images dynamically everywhere (and it works), but still my TabBar and navigationBar are not updated at 100%. – izik461 Aug 14 '19 at 11:19