简体   繁体   中英

UIImageView with full width and variable height

I am developing an app where I want the UIImageview like instagram feed. I set the leading and trailing space to mainview as zero so width is now 100% of screen. Now how do i set the height so that it varies depending on image's scale. I tried setting content mode to Aspect Fit, but its not working and blank spaces are coming in the left and right side for a portrait mode image

Sample Image i selected 所选图片

How it came after selecting in UIIMageView

UIImageView中的图像

To solve this issue you need to get Image dimension in Height and Width from server side for each image. Then Accroding to Image Width, Image Height, Screen width you have to calculate new Image Height and Set it to ImageView Height by taking Image View Height Constraint.

let calculatedImageHeight = (screenWidth * imageHeight)/imageWidth

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM