简体   繁体   English

具有全宽和可变高度的UIImageView

[英]UIImageView with full width and variable height

I am developing an app where I want the UIImageview like instagram feed. 我正在开发一个我想要UIImageview像instagram feed的应用程序。 I set the leading and trailing space to mainview as zero so width is now 100% of screen. 我将主视图的前导和尾随空间设置为零,因此宽度现在是屏幕的100%。 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 我尝试将内容模式设置为Aspect Fit,但无法正常工作,纵向模式图像的左右两侧都出现空白

Sample Image i selected 我选择的样本图片 所选图片

How it came after selecting in UIIMageView 在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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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