LeoMaer LeoMaer - 1 year ago 67
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

Answer Source

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
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download