Start a Project

How To Manage Dynamic Height In Collection View iOS

How To Manage Dynamic Height In Collection View iOS

Most of the time, we take labels inside the collection view.  We want the height of the collection view exactly equal to the label data height because it will not look good if the label data height is less than the collection view cell, it will show a blank space and if the label data height is more than the collection view then it will truncate the data.

Here I am discussing how to manage collection view cell height according to text label data.

Follow the steps :

Step 1: Go to the collection view cell class and create the outlet of the label.

Step 2: Go to MainViewController and create the outlet of the collection view.

Step 3: Now create the extension to calculate the height of the label.

Step 4: Now Register the collection view cell so that we can use it.

Step 5: After registering the collection view cell write their All delegate and data source method inside main controller class.

Step 6: Now your collection view cell height will automatically increase after calculating the height of the label.

So please follow the above step and if you have any issue or suggestion you can leave your query/suggestion in the comment section I will try to solve that.

Exit mobile version