简体   繁体   中英

UICollectionView Update Cellsizes after changing constraints

I am using autolayout to determine the cellsize (fixed with, variable height) and set all the necessary constraints in the storyboard. Autolayout works fine as long as I don't change the constraints.

But at Runtime I have to add buttons to some cells. I remove the bottom constraint of the last label, insert the button and add a constraint to the label above, one leading constraint to the cell and one to the bottom of the cell.

The problem is, that the cells size is not updated after this. I tried to call LayoutIfNeeded in the cell and in the collection view but that did not work. I think the constraints are set up correctly. The button appears at the right position but the cell just keeps the height for a cell without a button. How can I tell the CollectionView to update the cell sizes?

You could refer the below link probably you can get your answer with manually and automatically size of UICollectionViewCell.

How make a collectionViewCell auto size only by height?

==>如果需要动态设置UICollectionViewCells的大小,则可以使用UICollectionViewFlowLayout方法的itemSize属性设置UICollectionViewCell的大小,也可以使用委托方法collectionView:layout:sizeForItemAtIndexPath:。

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