Thanks for being a part of WWDC25!

How did we do? We’d love to know your thoughts on this year’s conference. Take the survey here

Programmatically Setting Constraints for CollectionViewCell Elements

Is there any possibility to update constraints for elements inside CollectionViewCell with button tap?

And where to put the code inside CellForItem or Inside CollectionViewCell Class File?

Button is inside the cell ?

It should be possible. Create the constraints and define IBOutlet.

Then, for cell for which you want to change the constraints, call,

cell.theConstraint.constant = newValue

If button is in cell, do it in the button IBAction

if button outside, in anotherView, call this in the IBAction for each cell you want to modify. You get the cell with

let cell = collectionView!.cellForItemAtIndexPath(indexPath)

I utilised above suggestion. But also tried using [NSLayoutConstraint] but it throws errors sometimes.

How to layout cell with two layouts with use of [NSLayoutConstraint] And how to implement it.

Programmatically Setting Constraints for CollectionViewCell Elements
 
 
Q