I have this code snippet:
func resizeImageViewToImageSize(_ imageView:UIImageView) {
let widthRatio = imageView.bounds.size.width / imageView.image!.size.width
let heightRatio = imageView.bounds.size.height / imageView.image!.size.height
let scale = min(widthRatio, heightRatio)
let imageWidth = scale * imageView.image!.size.width
let imageHeight = scale * imageView.image!.size.height
print("\(imageWidth) - \(imageHeight)")
imageView.frame = CGRect(x: 0,
y: 70,
width: imageWidth,
height: imageHeight)
imageView.center.x = view.center.x
}
I call it in viewDidLoad()
to resize my originalImageView
UIImageView:
resizeImageViewToImageSize(originalImageView)
And it successfully resizes my UIImageView, but in case I take a picture from Camera (on iPhone7+, for instance), my imageWidth and imageHeight are: 226.4 - 283.0
, which make my UIImageView very small in the center of the screen, as shown below:
What I would like to do is to have my originalImageView
to be larger in width and keep its scale ratio accordingly, like the mockup below, is that possible?