I have a UIcollectionview
. There are some cells of the Collectionview. Inside that CollectionviewCell
there is a textview. The textview's content is dynamic. So the cell height should be dynamic.
How to do that?
I have a UIcollectionview
. There are some cells of the Collectionview. Inside that CollectionviewCell
there is a textview. The textview's content is dynamic. So the cell height should be dynamic.
How to do that?
Use NSAttributedString in
sizeForItemAtIndexPath
to calculate rect for the height and width:1-Add
UICollectionViewDelegateFlowLayout
protocol2-Conform to protocol by implement the
sizeForItemAtIndexPath
method in your ViewController3-By the index of the cell get the text you have and caculate the hight and width of it
1) Override collectionflowlayout delegate method
2) In above method, Calculate the height of textview which contains dynamic length and add that value in your fixed height.
Ex. cellHeight = 100 + textview height. //100 is height which not contain textview height.
3) After calculating height, replace it in above method