Question

I have a bunch of objects, all equally spaced from each other. The constraints are set correctly for 3.5" screen, but for the 4" screen I want them farther apart (i.e. the distance between each object still the same, but larger).

I currently change constraints programmatically like this:

self.usernameVerticalSpace.constant = 256;

But if e.g. 8 constraints will be kept exactly the same as each other, but all increased at once, it seems like there should be a way to do that to one outlet, instead of 8 individual outlets. Is there a way to link all these constraints to one outlet, so I only have to change one value?

Was it helpful?

Solution

Have you heard about IBOutletCollection? When you link any object from IB to VC code, in popup window you can select IBOutletCollection Option.

Tell me if it is not useful or if more info needed

OTHER TIPS

You can create an IBOutletCollection like this in code

@IBOutlet var constraintsCollection: [NSLayoutConstraint]!

Then click inside the small circle infront of the line just added and drag to link each constraint you want to add to the constraintsCollection one after the other in IB.

enter image description here

Once you have added one by one all the constraints to the Constraint Collection, it will contain all constraints like shown below enter image description here

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top