Skip to content

Instantly share code, notes, and snippets.

@appshish
Last active April 9, 2017 18:47
Show Gist options
  • Save appshish/e89a6369dcf02ddc77c2 to your computer and use it in GitHub Desktop.
Save appshish/e89a6369dcf02ddc77c2 to your computer and use it in GitHub Desktop.
Resize Image in iOS Swift
// Courtesy: Hampton Catlin's gist.
// to resize an image to dimension 52x52
var newSize:CGSize = CGSize(width: 52,height: 52)
let rect = CGRectMake(0,0, newSize.width, newSize.height)
UIGraphicsBeginImageContextWithOptions(newSize, false, 1.0)
// image is a variable of type UIImage
image?.drawInRect(rect)
let newImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
// resized image is stored in constant newImage
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment