Advertisement
Guest User

Untitled

a guest
Sep 3rd, 2015
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. //
  2. // UIImageView+imageFrame.swift
  3. // Tindex
  4. //
  5. // Created by Koen Punt on 24-08-15.
  6. // Copyright (c) 2015 Koen Punt. All rights reserved.
  7. //
  8.  
  9. import UIKit
  10.  
  11. /** imageFrame Extends UIImageView
  12.  
  13. */
  14. extension UIImageView {
  15.  
  16. var imageSize: CGSize {
  17. get {
  18. if let image: UIImage = self.image {
  19. let widthRatio = image.size.width / self.frame.size.width
  20. let heightRatio = image.size.height / self.frame.size.height
  21. let ratio = maxElement([widthRatio, heightRatio])
  22. return CGSizeMake(image.size.width / ratio, image.size.height / ratio)
  23. }
  24. return CGSizeZero
  25. }
  26. }
  27.  
  28. var imageFrame: CGRect {
  29. get {
  30. if let image: UIImage = self.image {
  31. let size = self.imageSize
  32.  
  33. return CGRectMake((self.frame.size.width - size.width) / 2, (self.frame.size.height - size.height) / 2, size.width, size.height)
  34. }
  35. return CGRectZero
  36. }
  37. }
  38.  
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement