Skip to content

Instantly share code, notes, and snippets.

@krummler
Created April 20, 2020 11:58
Show Gist options
  • Save krummler/4d7d852458cd8a312f627ae79053189c to your computer and use it in GitHub Desktop.
Save krummler/4d7d852458cd8a312f627ae79053189c to your computer and use it in GitHub Desktop.
// Create an asset
let set = UIImageAsset()
// Define traits to be specific for the images
let darkTraits = UITraitCollection(traitsFrom: [UITraitCollection(userInterfaceStyle: .dark),
UITraitCollection(displayScale: someDarkImage.scale)])
let lightTraits = UITraitCollection(traitsFrom: [UITraitCollection(userInterfaceStyle: .light),
UITraitCollection(displayScale: someLightImage.scale)])
// Register the images alongside the traits
set.register(someDarkImage, with: darkTraits)
set.register(someLightImage, with: lightTraits)
// Generated a combined image
let combinedImages = set.image(with: .current)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment