CollectionView Layout height from imageView

Hi, I need help with layout in collection view. I need to make cell with screen width and auto height taking from image. How can I make this?

@pietrzakmarcin Thanks very much for your question!

For getting the width of the screen, you’d use:


For getting the height from the image, you’d use:


I hope this helps!

All the best!

If you’re going to make each cell as wide as the screen, you should probably be using a UITableView instead. Drop your image into your prototype cell, and then set a height constraint on the image to anything. Link that height constraint as an @IBOutlet in your view (The UITableViewCell, not the UITableViewController), and then when you configure the cell, you can set that height constraint to be the correct thing based on your image.

This topic was automatically closed after 166 days. New replies are no longer allowed.