ExtensionUIImageView.swift 812 B

1234567891011121314151617181920212223242526272829303132
  1. import Foundation
  2. import UIKit
  3. extension UIImageView{
  4. @IBInspectable
  5. var resizableImage: UIImage? {
  6. get {
  7. return self.image
  8. }
  9. set {
  10. if let image = newValue {
  11. self.image = image.resizableImage(withCapInsets: UIEdgeInsets(top: 20, left: 20, bottom: 20, right: 20)).withRenderingMode(.alwaysTemplate)
  12. }
  13. }
  14. }
  15. }
  16. extension UIImageView{
  17. func getRatioHeight() -> CGFloat {
  18. guard let image = self.image else { return 0}
  19. let myImageWidth = image.size.width
  20. let myImageHeight = image.size.height
  21. let myViewWidth = self.frame.size.width
  22. let ratio = myViewWidth/myImageWidth
  23. let scaledHeight = myImageHeight * ratio
  24. return scaledHeight
  25. }
  26. }