spectre_d2
spectre_d2

Reputation: 203

Change collection view constraints programmatically

I have create a collection view in my storyboard and add constraints. Now I need to change the collection view constraint for a specific condition and I want to do it programmatically in my class. I have an IBOutlet for the collection view. What parameter needs to be changed?

Upvotes: 1

Views: 1175

Answers (3)

Rodrigo Fuscaldi
Rodrigo Fuscaldi

Reputation: 182

  1. Add the constraints normally in the collection view
  2. Select the constraint you want to modify, hold Control and drag to your class
  3. When you want your constraint to be changed, type nameOfYourConstraint.constant = 100 // Int

Upvotes: 2

Prashant Tukadiya
Prashant Tukadiya

Reputation: 16456

First create IBOutlet of constraints required to changed by dragging to ViewController

The constant value needs to be cahnged, e.g.:

self.outlet.constant = 50

Don't forget to call self.view.layoutIfNeeded after modifying the constant.

Upvotes: 1

Sumeet Mourya
Sumeet Mourya

Reputation: 434

You need to create IBOutlets of the constraints, and update the constraints value according to your condition.

Upvotes: 1

Related Questions