Skip to content

Instantly share code, notes, and snippets.

@kineticac
Created March 4, 2016 02:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kineticac/5416cb64ed9b8d9a0b08 to your computer and use it in GitHub Desktop.
Save kineticac/5416cb64ed9b8d9a0b08 to your computer and use it in GitHub Desktop.
UIImageView's image does not respect ScaleAspectFit contentMode unless the image originated as a CGImage
// Assume these return images from disk purely as CI and CG images
let ciImage = createPureCIImage()
let cgImage = createPureCGImage()
// This fetches the imageView reference
let imageView = getUIImageView()
imageView.contentMode = .ScaleAspectFit
// this will not show aspect fit
imageView.image = UIImage(CIImage: ciImage)
// this WILL show aspect fit
imageView.image = UIImage(CGImage: cgImage)
// this will also show it, assume convertCIImagetoCGImage does just that
imageView.image = UIImage(CGImage: convertCIImagetoCGImage(ciImage))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment