Suragch
Suragch

Reputation: 512246

How to edit multiple constraints at once in Xcode's Interface Builder

I have a layout of UIButtons that looks like this:

enter image description here

The horizontal spacing between the buttons is 8. I would like to change this to 4. Of course, I could change them one by one, like this:

enter image description here

But there are a lot of buttons and I don't really feel like doing that.

I tried selecting multiple buttons and then added a horizontal space constraint of 4 but that just adds constraints. It doesn't update the old constraints. This creates conflicting constraints with the old ones.

I didn't see anything to solve this in the Editing Auto Layout Constraints documentation.

Upvotes: 5

Views: 2175

Answers (5)

Jigar Oza
Jigar Oza

Reputation: 665

I am agree with the answer of @Leo and up voted as well :)

Just adding to it, if someone would like to make it more easier, he can use the filter option given below the constraints.

For example to find all the leading constraints one can search for " = leading" word or "trailing = " for trailing constraints or other similar search string.

You can see this from the GIF as well.

enter image description here

Upvotes: 2

Sunny Shah
Sunny Shah

Reputation: 13020

One of the way is to create spacer views, With each view width equal to the first one. Set your Button constraint to leading and traling to the spacer view. and if you change first width of spacer view it will change all othes view width.

Upvotes: 4

Leo
Leo

Reputation: 24714

Just use Command + click to select multi constraits,

like the gif

enter image description here

Upvotes: 6

Varun Naharia
Varun Naharia

Reputation: 5428

You just have to select all button and move where you want them and then you have to just update the constraint.

Update Constraints

Upvotes: 0

Vakas
Vakas

Reputation: 6462

You have to do that one by one. There isn’t any way that you select all of them an edit their values.

Upvotes: 0

Related Questions