Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS dark mode - image assets not redrawn

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.

like image 602
izik461 Avatar asked Aug 13 '19 11:08

izik461


1 Answers

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!

like image 65
izik461 Avatar answered Oct 16 '22 23:10

izik461