Skip to content

Instantly share code, notes, and snippets.

@randhirraj3130
Created December 20, 2016 07:51
Show Gist options
  • Save randhirraj3130/f95d718162fca8258e888bf7921086b0 to your computer and use it in GitHub Desktop.
Save randhirraj3130/f95d718162fca8258e888bf7921086b0 to your computer and use it in GitHub Desktop.
how to crop image in swift 3.0
extension UIView
{
func getCropedImage(frame: CGRect) -> UIImage
{
UIGraphicsBeginImageContextWithOptions(frame.size, false, 0)
drawHierarchy(in: CGRect(x: -frame.origin.x, y:-frame.origin.y, width: self.bounds.size.width, height: self.bounds.size.height), afterScreenUpdates: true)
let snapshotImage = UIGraphicsGetImageFromCurrentImageContext()!
UIGraphicsEndImageContext()
return snapshotImage
}
}
// FullImage.image = FullView.getCropedImage(frame: CropView.frame)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment