Adjust UICollectionViewCell to fit content

久未见 提交于 2019-12-10 20:21:36

问题


I have a label that is set to resize to its content. I want the UICollectionViewCell to do the same. I cannot find anyway to implement that.

A picture describing my current arrangement can be found below:


回答1:


I think you'll want to implement the UICollectionViewDelegateFlowLayout method collectionView:layout:sizeForItemAtIndexPath: to adjust the size of each collection item based on the contents.

Here's a tutorial on Collection Views that covers this specific topic.




回答2:


Use "Autolayout" in cell's Interface Builder document. After setting constraints, your cell frame is going to dynamically change.




回答3:


configure collection:

YOU_Collection.layout.estimatedItemSize = CGSize(width: 1, height: 1)

and in cell add label constraints (top and bottom)



来源:https://stackoverflow.com/questions/26184098/adjust-uicollectionviewcell-to-fit-content

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!