# CollectionView Layout height from imageView

**URL:** <https://forums.kodeco.com/t/collectionview-layout-height-from-imageview/36098>\
**Category:** Swift\
**Created:** [October 31, 2017, 12:41pm UTC](https://forums.kodeco.com/t/collectionview-layout-height-from-imageview/36098 "2017-10-31T12:41:57Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![pietrzakmarcin](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/pietrzakmarcin/32/81494_2.png) [@pietrzakmarcin](https://forums.kodeco.com/u/pietrzakmarcin)\
**Post date:** [October 31, 2017, 12:41pm UTC](https://forums.kodeco.com/t/collectionview-layout-height-from-imageview/36098/1 "2017-10-31T12:41:57Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![syedfa](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/syedfa/32/101500_2.png) [@syedfa](https://forums.kodeco.com/u/syedfa)\
**Post date:** [November 1, 2017, 3:05am UTC](https://forums.kodeco.com/t/collectionview-layout-height-from-imageview/36098/2 "2017-11-01T03:05:02Z")

</div>

@pietrzakmarcin Thanks very much for your question!

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

`UIScreen.main.bounds.size.width`

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

`imageView.image.size.height`

I hope this helps!

All the best!

---

<div class="post-metadata">

**Author:** ![gargoyle](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/gargoyle/32/107285_2.png) [@gargoyle](https://forums.kodeco.com/u/gargoyle)\
**Post date:** [November 5, 2017, 5:49am UTC](https://forums.kodeco.com/t/collectionview-layout-height-from-imageview/36098/3 "2017-11-05T05:49:08Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://s3.amazonaws.com/cdn.raywenderlich.com/community/forum-assets/noun-game-ghost-878668.png) [@system](https://forums.kodeco.com/u/system)\
**Post date:** [April 16, 2018, 4:41am UTC](https://forums.kodeco.com/t/collectionview-layout-height-from-imageview/36098/4 "2018-04-16T04:41:58Z")

</div>

Closed on April 16, 2018, 4:41am UTC

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