简体   繁体   中英

How to adjust collection view cell height in swift ios?

My cell contains label and textview and i want to adjust the textview's height 在此处输入图片说明

the cell height should also be adjusted. please help

Thanks

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM