0

My cell contains label and textview and i want to adjust the textview's height enter image description here

the cell height should also be adjusted. please help

Thanks

Angad Singh
  • 59
  • 1
  • 1
  • 5
  • if you are taking `textView` inside cell, the cell height will not be adjust based on `textView` content. It will scroll inside the `textView`. So take only label – Shabbir Ahmad Mar 12 '18 at 10:49
  • Possible duplicate of [CollectionView dynamic height with Swift 3 in iOS](https://stackoverflow.com/questions/45204283/collectionview-dynamic-height-with-swift-3-in-ios) – Ahmad F Mar 12 '18 at 10:59

2 Answers2

0

You have two options to achieve this functionality.

1) Use a tableview and use autolayout so that cell height increases automatically according to the content.

2) Use collection view and calculate the height of the textview in this method and specify the cell size in this method sizeforitematindexpath.

Here is the second method:

Once the textis set to the textview then change the textview frame to

textview.frame = CGRect(x: textview.frame.orgin.x, y:textview.frame.orgin.y, width: textview.frame.width, height = textview.contentSize.height)

Now calculate the textview height in cellForItemAtIndexPath method and add that height to the cell height.

Amrit Sidhu
  • 1,870
  • 1
  • 18
  • 32
0

Hi this is the solution for collectionViewCell AutoAdjust cell height Size. Check below link it should works fine.

https://medium.com/@wasinwiwongsak/uicollectionview-with-autosizing-cell-using-autolayout-in-ios-9-10-84ab5cdf35a2

Ram
  • 858
  • 1
  • 14
  • 19