Given a UIImageView using AspectFit how can I calculate the height of any whitespace above and below the UIImage?
Asked
Active
Viewed 88 times
-1
-
please elaborate or give an example to clarify – Samarth Kejriwal Jul 21 '17 at 18:21
-
Do some math based the frame size of the image view and the size of the image. – rmaddy Jul 21 '17 at 20:39
1 Answers
-1
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

Vasil Hristov
- 132
- 4