LeoMaer LeoMaer - 9 months ago 22
iOS Question

iOS: I get many `UIImage` from network, how can I know their `aspect ratio`?

How can I get the aspect ratio for the image which comes from the server?

EDIT:If I get many

in the network, how can I get them by using
async function
? and in the block to get their
aspect ratio


Once you download the image, create an UIImage instance by using the downloaded data then through size property, you will be able to determine the height and width of the actual image downloaded :

let image = UIImage(data: <imageDownloadeddata>)
let imgWidth = image.size.width
let imgHeight = image.size.height