Suppose you have a UIImage with dimensions 768 x 592 of width and height respectively, the height always remains the same, where the device that it rotates, for example, in sizes higher (iPad), changes the image width to 1024, and the height remains equal.
What can you do to preserve the aspect of the image, scale it to the right size, for example, if you know that incoming images are always the same size, say, for example, 1280x740, you can set UIImage to .ScaleToFill and calculate as follows:
(widthOfTheImage / heightOfTheImage) * heightWhereYouWanToSet = widthYouHaveToSet
For instance:
(1280 / 740) * 592 = 1024
And I need to set width in my UIImage in order to maintain the aspect ratio of the image when changing its width.
I hope you understand where I'm trying to tell you.
source share