Automatic Resize images in collection view - ios

I used an Image inside collection view(entire cell). Images I'm getting from API. I need to resize width & height of collection view & cell based on image size dynamically. Help me out.

Related

Positioning of cell according to the hight of previous cell in collection view in iOS Swift

I am working on a wallpaper app with images of different sizes. I am calculating the sizes of cells dynamically with respect to image size. But how I can set the positions of cells dynamically with respect to its upper cell .. see the screenshots below:
How can I create a dynamic layout like this.. see screenshot:

Existing flow layout for variable width uicollectionview

Is there any existing flow layout which can support a collection view which the user can scroll a collection of images in a horizontal direction but have the images have variable width and same height? I have one sort of working but it sometimes randomly spaces the images. Thanks.

ImageView in self-sizing table cell uses height of image before Aspect Fit is applied

I have an ImageView inside of a self-sizing table cell that has a content mode of Aspect Fit.
When the table fully loads the image itself looks great, it resizes to fit within the width of the cell while still keeping the original ratio.
However, the height of the table cell is as large as if the Aspect Fit content mode was never applied to the image view.
The red in this image is the image view and the space above and below the actual image is what I'm trying to avoid.
When I replace Aspect Fit with Aspect Fill, this is what the same cell looks like:
This is what I mean when I say it looks like the image view is using the height of the image before Aspect Fit is applied.
Am I missing a constraint or setting in the ImageView?
Any help is appreciated!
If the images are being downloaded from a server, they will take a second or a millisecond to be downloaded. The time they take to download is noticeable to the user. The best user experience is explicitly setting the height and width before the image is downloaded. If you are using a third party API to fetch the image (i.e. facebook or youtube API), the return will include the image URL along with the height and width for the image. This way you can set the height and width of the cell and then wait for the image to download without any interruption or change in the size of cells. This would be the best way to do it. By having the height and width set explicitly, you don't need to worry as much about the content mode to use for the image view. I would only recommend using a self sizing UITableViewCell if you are explicitly setting the height and width of image view within that cell. I hope this helps!
I just saw your most recent comment. You can adjust the size of each image view within each cell depending on the image that is being returned. You don't need to set a fixed height for the image view. You can change the height of each cell depending on the image that is in that cell. I would just recommend doing this before the image is downloaded.
If you are using storyboard, then one way to do this is creating an outlet for the height constraint of the image view.

How to achieve resizing of UITableView cells like instagram?

I need to be able to resize an UIImageView according to the size of the image which is in aspect fit.
and also i need to be able to resize the cell that the image is contained in.
A example would be the instagram app, they have different size images yet the cells are sized appropriately?
Use auto layout when creating your table view cells
Set the table view rowHeight to equalUITableViewAutomaticDimension.
Set theestimatedRowHeight or implement the height estimation delegate method.
You need to adopt the dynamic cell height. Now that cell will automatically determine its height from its content view subviews, make sure you have set your auto layout constraints carefully. Set content mode of UIImageView to aspect fit.
Below are some links to follow:
1. Rey wenderlich
Site Point

Fixing imageview frame according to image

I am showing images downloaded from an URL in a table view whose custom cells have UIImageViews.
Now my requirement: I want to fix the height of that imageview and cell according to the height of that image in that cell.
The steps to perform are the following: (I won't write the code for you, just guide)
in heightForRow method you pick the image from the data source
then you learn its size (image.size)
return the value like
size.height+SOME_CONSTANT, where SOME_CONSTANT is the space for
other content

Resources