Xcode6: Is there an easy way to copy constraints between size classes?

I set limits on the wAny hAny size class, and it worked on iPhone and iPad simulators.

wAny hAny

Then I switched to the wAny hCompact class and made some changes

wAny hCompact

It looks good in iPhone landscape mode, but doesn't change anything on the iPad, because the iPad is wRegular hRegular. I am trying to apply these restrictions to the wRegular hAny class, but cannot find a quick way to do this. It makes no sense to manually manually change all the restrictions. I found that if I double-click the restriction in the Inspector panel, there you can set a restriction on other size classes. But this is only for one limitation ...

inspector

So, is it possible to apply all the restrictions of one class to another?

+5
source share
4 answers

Thought I'd post this, although Hannes's answer was accepted, as it might be useful to someone. You can bulk update size classes for your constraints by directly editing the source code. As a rule, a bad idea for editing IB created XML directly, but I did the update using the good old find and replace, and it saved me a lot of time.

The obvious caveat: make a backup copy of the file in case something is not so terribly wrong ...

Look for nodes like:

<variation key="heightClass=(Size Class)-widthClass=(Size Class)"> 

In my case, I wanted to translate all my Compact Width / Compact Height restrictions to Any Width / Compact Height "and was able to achieve this by searching / replacing" -widthclass = compact "with an empty string to change" heightclass = compact-widthclass = compact "only for " heightclass = compact ".

To go to the source code, right-click the storyboard file in xcode and select " Open As> Source Code "

Pretty simple in this case and much easier than doing it in IB, as I had a lot of restrictions for updating.

+10
source

Select Constraints in the left pane. (Select all restrictions). Then click on the Attribute Inspector in the right pane. Then add the class you want to add, for example, how we add user interface elements.

Ref image

+2
source

No, you cannot edit all restrictions together.

But for each, you simply click this plus button before Installed and add wAny hAny and select it. Then your restriction will apply to all size classes. You can add additional parameters and thus decide when restrictions apply.

0
source

Find and replace the code: I did this to go from compact to any / any. It works for me. Find - heightclass = regular-widthclass = compact Replace - default

For other size clusters, find the size string accordingly and resize. Kudos !!

Update restrictions at the end. Otherwise, everything will not be as expected.

0
source

Source: https://habr.com/ru/post/1201994/


All Articles