Height of whitespace above and below UIImage in UIImageView

100 Views Asked by At

Given a UIImageView using AspectFit how can I calculate the height of any whitespace above and below the UIImage?

1

There are 1 best solutions below

0
On

You can do it easily when calculate the scale of the image:

let horizontalRatio = image.size.width / uiimageView.frame.size.width
let verticalSpacing = uiimageView.frame.size.height * horizontalRatio

And probably it is vertically in the middle

let whitespaceAbove = verticalSpacing / 2
let whitespaceBelow = verticalSpacing / 2