Skip to content

Instantly share code, notes, and snippets.

@laevandus
Created October 25, 2020 01:39
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 laevandus/3367650ce769ede040a66805f89477ef to your computer and use it in GitHub Desktop.
Save laevandus/3367650ce769ede040a66805f89477ef to your computer and use it in GitHub Desktop.
// Scaling the full image
let originalImage = UIImage(named: "example_photo.jpg")!
var targetSize = CGSize(width: 100, height: 100)
imageView.image = ImageScaler.scaleToFill(originalImage, in: targetSize)
// Scaling only a small part of the image
let originalImage = UIImage(named: "example_photo.jpg")!
var fromRect = CGRect(x: 362.0, y: 449.0, width: 260.0, height: 160.0)
var targetSize = CGSize(width: 100, height: 100)
imageView.image = ImageScaler.scaleToFill(originalImage, in: targetSize, from: fromRect)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment