Guest User

Untitled

a guest
Jan 23rd, 2018
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. extension UIImage{
  2.  
  3. func resizeImageWith(newSize: CGSize) -> UIImage {
  4.  
  5. let horizontalRatio = newSize.width / size.width
  6. let verticalRatio = newSize.height / size.height
  7.  
  8. let ratio = max(horizontalRatio, verticalRatio)
  9. let newSize = CGSize(width: size.width * ratio, height: size.height * ratio)
  10. UIGraphicsBeginImageContextWithOptions(newSize, true, 0)
  11. draw(in: CGRect(origin: CGPoint(x: 0, y: 0), size: newSize))
  12. let newImage = UIGraphicsGetImageFromCurrentImageContext()
  13. UIGraphicsEndImageContext()
  14. return newImage!
  15. }
  16. }
Add Comment
Please, Sign In to add comment