'Do you know where’s the Vary for Traits in Xcode 13?
I can't find Vary for Traits in Xcode 13. Thanks in advance for any help!
Solution 1:[1]
You can set Trait specific variations in the Attributes and Size Inspector panes.
For example, suppose we have this layout:
with Stack View properties:
But -- when we have a Regular Width trait, we want it to look like this:
with these Stack View properties:
Switch back to our original layout (Vertical stack view, spacing: 8, Height: 120).
Select the stack view, and in the Attributes Inspector pane, click the +
button to the left of Axis and from the popup select Width -> Regular
/ Height -> Any
:
When we click the Add Variation
button, we'll see a new wR
variation where we can select Horizontal
:
Now click the +
to the left of Spacing and again select Width -> Regular
/ Height -> Any
:
When we click the Add Variation
button, we'll see a new wR
variation where we can change 8
to 32
:
Now we select the Height constraint, and in the Size panel click the +
to the left of Constant and again select Width -> Regular
/ Height -> Any
:
When we click the Add Variation
button, we'll see a new wR
variation where we can change 120
to 64
:
Now when we switch the orientation in Storyboard / Interface Builder (and when we rotate the device at run-time), we'll get our desired result.
Solution 2:[2]
According to this, the only work around is doing the following:
- You set constraints for the active size class
- Trait Variations need to be enabled in the File Inspector tab
- After that you can manually add traits by clicking the plus next to a property (it'll use the active size class but you can modify it while creating too)
Unfortunately, this only works for properties, and not constraints. There is no other work around for this.
Everyone who has these problems should post bug reports to let the Xcode developers know.
Solution 3:[3]
I found one solution, let say you have leading, trailing, top and bottom constraint at 0 for the portrait. Now in the bottom bar, above the log window, tap to 'Orientation' to put the views in the landscape. Now find the constraint you want to change for that variation and double click on that constraint, then tap on + icon beside the Constant field and add a new variation, in this example for the landscape. Then change a value and those values will be implemented, one for portrait one for the landscape.
Solution 4:[4]
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | DonMag |
Solution 2 | krmogi |
Solution 3 | clopex |
Solution 4 | Suraj Rao |